﻿// JavaScript Document
jQuery(function( $ ){
	
	$('img[@src$=.png],.affect,.use').ifixpng(); 
	
/*	var prodnum = $(".sub").length	
	alert(prodnum)
	var boxheight = prodnum*135
	$(".section").css("height",boxheight)
*/
	$('#content').attr({scrollTop:0,scrollLeft:0});
	$.localScroll.hash({
		target: '#content', 
		axis:'xy',
		queue:true,
		duration:1500
	});

	var $last = $([]);
	
	$.localScroll({
				  
		target: '#content', 
		axis:'xy', 
		queue:true,
		duration:1000,
		hash:true,
		onBefore:function( e, anchor, $target ){
			$last.removeClass('scrolling');
			$last = $(this).addClass('scrolling');
			if( this.blur )
			this.blur();
			},
		onAfter:function( anchor ){
			$last.removeClass('scrolling');
		}
	});
	
	 $("#scrollable").scrollable({
			size: 3,
			items:'.items',
			horizontal:false
	 });
	 
	

	 
	 var urlTxt = location.href;
	 var urlindex = urlTxt.split("#section");
	 urlindex = Number(urlindex[1]);
	 tempindex = isNaN(urlindex)
	 
	 if ((tempindex==false)&&(urlindex<11)) {
		
		//alert("url")
		urlindex = urlindex-1;
	switch (urlindex) {
		
			case 0: case 1: case 2: 
				$("#scrollable").scrollable("setPage", 0, [300]); 
				break;
			case 3: case 4: case 5: 
				$("#scrollable").scrollable("setPage", 1, [300]); 
				break;
			case 6: case 7: case 8:
				$("#scrollable").scrollable("setPage", 2, [300]); 
				break;
			case 9:
				$("#scrollable").scrollable("setPage", 3, [300]); 				
			default:
				$("#scrollable").scrollable("setPage", 0, [300]); 
				break;
		}
		//loadPrice(urlindex);
		
	 } else {
		 
		$("#scrollable").scrollable("setPage", 0, [300]);  
 		//swfobject.embedSWF("price.swf", "price1", "250", "23", "9.0.0", false, priceflashvars, priceparams, priceattributes);
		 
	 }
	 

	 
/*	 $('.items').find('a').click(function(){
			
		  //$('.active').ifixpng(); 	
		  var index = $('.items').find('a').index(this);
	      loadPrice(index);
		  							
											
	  });*/
	 
	 

	 
	 $('.tvcView').click(function(){
								  
			$('.tvcView').animate({
				width:"0",
				left:"-40px"
			},600);			
			$('#tvcBody').show();
			$('#tvcBox').show();
			var flvflashvars = {};
			flvflashvars.urlDefaultFLV ="flv/OlayDefinity.flv";
			swfobject.embedSWF("flvplayer.swf", "flvPlay", "344", "244", "9.0.0", false, flvflashvars);
			//$('#flvplayer').playVideo("/test.flv")

	  });
	 
	 $('.close').click(function(){
								
		closeTVC();
		
	 });
	 
	 $('#tvcBody').click(function(){
		
		closeTVC();
								  
	});
	 

	
});

function loadPrice(index) {
	//alert(index+""+typeof(index))
	var price = ['RMB 180/50ML','RMB 120/75ML','RMB 130/50G','RMB 120/150ML','RMB 130/5片','RMB 160/50ML','RMB 130/50ML','RMB 120/50G','RMB 130/150ML','RMB 130/5片面膜','RMB 80/125G','RMB 160/30ML','RMB 120/15G','RMB 110/100G']	
	
	var priceDivId = "price"+ (index+1)
	priceflashvars.priceTxtContent = price[index]
	swfobject.embedSWF("price.swf", priceDivId, "250", "23", "9.0.0", false, priceflashvars, priceparams, priceattributes);
	
}

function closeTVC(){
 
	$('#tvcBody').hide();
	$('#tvcBox').hide();
	$('#flvplayer').remove();
	$("<div id='flvPlay'></div>").appendTo('#tvcPlayer');
	$('.tvcView').animate({
		width:"40px",
		left:"0"
	},600);

}