// JavaScript Document

var nav = {
    alphas : ['0.0','0.25'],
	displays : ['none','block'],
	time : 360,
    init : function(){
	   $('h2#home').mouseover(function(){
	      $('div#nav_bg').animate({'opacity': nav.alphas[1]}, nav.time,function(){
		     $('table#nav_txt').css('display',nav.displays[1]);
		  });
		  $(this).html('<a href="index.php">HOME</a>');
	})
	   nav.timer = window.setTimeout('nav.hides()', nav.time*1.0);
	} ,
	hides : function(){
	   $('table#nav_txt').hover(function(){},function(){
		    $('table#nav_txt').css('display',nav.displays[0]);
		    $('div#nav_bg').animate({'opacity': nav.alphas[0]}, nav.time*.5);
			$('h2#home').html('<a href="index.php">HOME</a>');
			
	     });
		 
	}
};

var footer = {
	isOpen:false,
	init:function(){
	  var min = '-536px';
	  var max = '0px';
	  footer.open(max);
	  footer.hide(min);
	  footer.selects();
	},
	open:function(max){	  
	  $('div.footer_data').click(function(){
		  footer.goopen(max);
	  });
	},
	goopen:function(max){
	   if(!footer.isOpen){
		  $("#footer").stop();
		 $("#footer").animate({'margin-bottom': max}, 120);
		 $("#open").css('display','none');
		 $("#close").css('display','block');
		 //$("#footerdata").animate({'opacity': '0'}, 360);
		 footer.isOpen = true;
	    }
	},
	hide:function(min){
	  $("#footer").mouseleave(function(){
		  footer.gohide(min);
	  });
	   
	  $("#close").mousedown(function(){
		  footer.gohide(min);
	  });
	  
	  footer.ezbAddEvent(window,"load",function(e){
		footer.ezbAddEvent(document,"mouseout",function(e){
		  e = e ? e : window.event;
		  var from = e.relatedTarget || e.toElement;
		  if(!from || from.nodeName == "HTML")footer.gohide(min);
        });
      });
	},
	ezbAddEvent:function(object,oEvent,fnctn){
	  if(object.addEventListener) object.addEventListener(oEvent,fnctn,false);
	  else if(object.attachEvent) object.attachEvent("on" + oEvent, fnctn);
    },
	gohide:function(min){
		if(footer.isOpen){
		  $("#footer").stop();
		  $("#footer").animate({'margin-bottom': min}, 120);
		  $("#open").css('display','block');
		  $("#close").css('display','none');
		  //$("#footerdata").animate({'opacity': '1'}, 120);
		  footer.isOpen = false;
		}
	},
	selects:function(){
	  $('p#select > a').each(function(index){
		$(this).bind('mouseover',function(){
		  $('p#select > a').removeClass('onfocus');
		  $('p#select > a > span:last-child').css('display','none');
		  $('p#select > a > span:first-child').css('display','inline');
		  
		  $(this).addClass('onfocus');
		  $(this).find('span:first-child').css('display','none');
		  $(this).find('span:last-child').css('display','inline');
		})
	  });
	}
};

var screenCon = {
	init:function(){
		$('#sceenController').click(function() {
  var Request = new Array();//保存参数  
  var s = location.search.substring(1);  
  if(s && s!="")  
  {  
  var list = s.split("&");  
  for(var i=0;i<list.length;i++)  
  {  
  var pair = list[i].split("=");  
  if(pair[0]&&pair[0]!="") Request[unescape(pair[0])] = unescape(pair[1]);  
  }  
  }  
  var fullscreen=Request["fullscreen"];  
  if(fullscreen!="yes")  
  {  
  var file=self.location;  
  var a = window.open("about:blank","","fullscreen=yes");  
  self.opener=null;  
  self.close();  
  a.location=file +"?fullscreen=yes";  
  }   
		});
	}
};

var photo = {
	names : ['01','02','03'],
	urls : [homeimg,homeimg1,homeimg2],
	num : 0,
	timer : null,
	init : function(){
		$('img#photo').attr('src',function(){
			  return photo.urls[photo.num];
		});
		photo.timer = window.setTimeout("photo.getfadeout()",6000);
	},
	getfadeout : function(){
		$('img#photo').animate({opacity:0.0},
		                        360,
								"linear", 
								function(){ 		
		    if(photo.num < photo.urls.length - 1 ){
			   photo.num += 1 ;	
		    }
		    else
		    {
		      photo.num = 0;
		    };
		 
		    $('img#photo').attr('src',function(){
		      return photo.urls[photo.num];
		     });
		
		     $('img#photo').animate({opacity:1.0},
		                        360,
								"linear", 
								function(){ 		
                photo.timer = window.setTimeout("photo.getfadeout()",6000)
			 });
		 })
	}
};


var model_photo = {
	names : ['01','02','03'],
	urls : typeof(global_urls)=='undefined'?new Array():global_urls,
	num : 0,
	timer : null,
	init : function(){
		$('img#model_photo').attr('src',function(){
			  return model_photo.urls[model_photo.num];
		});

		$('a#next').click(function(){
			model_photo.gonext();
		});
		$('a#prev').click(function(){
			model_photo.goprev();
		});
		$('font#titol').text('/' + String(model_photo.urls.length));
		$('font#num').text(String(model_photo.num + 1));
	},
	gonext : function(){
		$('img#model_photo').animate({opacity:0.0},
		                        360,
								"linear", 
								function(){ 		
		    if(model_photo.num < model_photo.urls.length - 1 ){
			   model_photo.num += 1 ;	
		    }
		    else
		    {
		      model_photo.num = 0;
		    };
		 
		    $('img#model_photo').attr('src',function(){
		      return model_photo.urls[model_photo.num];
		     });
		
		     $('img#model_photo').animate({opacity:1.0},
		                        360,
								"linear");
								
			$('font#num').text(String(model_photo.num + 1));
		 })
	},
	goprev : function(){
		$('img#model_photo').animate({opacity:0.0},
		                        360,
								"linear", 
								function(){ 		
		    if(model_photo.num <= 1 ){
			   model_photo.num = model_photo.urls.length - 1 ;
		    }
		    else
		    {
		      model_photo.num -= 1 ;	
		    };
		 
		    $('img#model_photo').attr('src',function(){
		      return model_photo.urls[model_photo.num];
		     });
		
		     $('img#model_photo').animate({opacity:1.0},
		                        360,
								"linear");
								
			$('font#num').text(String(model_photo.num + 1));
		 })
	}
};

var sound = {
	init : function(){
		//alert('1');
		$.fn.soundPlay({url: 'music/I_Like_It_I_Love_It.mid',playerId: 'embed_player', command: 'stop'});
		
		$('#stop').click(function(){
			$.fn.soundPlay({url: 'music/I_Like_It_I_Love_It.mid',playerId: 'embed_player', command: 'play'});
			$(this).css('display','none');
			$('#play').css('display','inline');
		});
		//alert('3');
		$('#play').click(function(){
			$.fn.soundPlay({url: 'music/I_Like_It_I_Love_It.mid',playerId: 'embed_player', command: 'stop'});
			$(this).css('display','none');
			$('#stop').css('display','inline');
		})
	}
};

$(document).ready(function(){
	photo.init();
	sound.init();
	footer.init();
	nav.init();  
	screenCon.init();
  }
);
