
$(document).ready(function() {
/*--------------------- Fix js -----------------------*/
digic({ pluginpart:'/js/xmlpluginpart.xml', checkbrowser:false });	
	digip.regs(['superfish','cycle', 'fancybox','jCarouselLite','lightbox','jprintnow']);
	window.onLoad = function() {};
	loadcatmenu(1245,1230);
	loadMenuProduct(1224,320);
	LinkWeb();
	PopupGalleryPhoto();
	contentDetaiProduct();
	fixJs();
	digip.recall('cycle',".HotNews_Scroll ul",{
		fx:'fade',
		timeout: 4000
	});	
	digip.recall('cycle', '.Banner_Scroll ul', {
		fx:'fade', 
		speed:2000,
		timeout: 5000,
		next:'.Banner_Scroll .Next',
		prev:'.Banner_Scroll .Prev'
	});
	digip.recall('cycle', '.AD_Fade ul', {
		speed:  '1000', 
		pager:	'.Nav'
	});	
	digip.recall('jCarouselLite', '.AD_Scroll .ItemScroll', {
		visible: 3,
		auto: 3000,
		speed: 2000,
		btnNext: '.AD_Scroll .next',
		btnPrev: '.AD_Scroll .prev'
	});	
	digip.recall('jCarouselLite', '.MenuCategoryScroll .ListItems', {
		visible: 5,
		vertical:true,
		btnNext: '.MenuCategoryScroll .next',
		btnPrev: '.MenuCategoryScroll .prev'
	});
	if($(".JW-PlayerList").size() > 0){
		loadscroll(".JW-Scroll");
	}
	untilDetail();
	binHeightContent();
});

var LinkWeb = function(){
	$(".lienket").each(function(){
		var $this = $(this);
		$("span",$this).click(function(){
			var check = $(".ListItem",$this).css("top").replace("px","");
			if(check < -999){
				$(".ListItem",$this).stop().css({"z-index":"3","height":"auto"}).animate({
					top:-($(".ListItem",$this).height()-3)				
				},1);
				$(".ListItem a",$this).click(function(){
					$(".ListItem",$this).stop().css({"z-index":"-3","height":"0"}).animate({top:"-9999px"},1);
				});
			}
			else{
				$(".ListItem",$this).stop().css({"z-index":"-3","height":"0"}).animate({top:"-9999px"},1);
			}
		});
		$($this).mouseleave(function(){$(".ListItem",$this).stop().css({"z-index":"-3","height":"0"}).animate({top:"-9999px"},1);});
	});	
}
var mainmenu = function(){
	digip.recall('superfish','.sf-menu',{
		autoArrows:false,
		dropShadows:false,
		delay:300,
		animation:{opacity:'show',height:'show'},
		speed:0
	});	
}
var loadMenuProduct = function(pageId,CatID){
	var Id = $("#"+pageId);
	var urlremote = '/WebPart/ECommerce/Products/AjaxProductBackend.ashx?&cmd=0&catid='+CatID+'&t='+ new Date().getTime();
	$.ajax({
		type:"GET",
		url: urlremote, 
		success: function(msg){
			if (msg.length > 0){
				$(Id).append(msg.replace(/{PageId}/gi,'1245'));
				$("li.level1",Id).each(function(){
					$(this).append("<ul class='level2'><li><a href='"+$('a',this).attr('href')+"'><img src='"+$('a',this).attr('rel3')+"'/></a></li></ul>");
				});			
			}			
		}
    });
}
var loadcatmenu = function(pageId,detaiId){
	var id = $("#MenuCategory");
	var urlremote = '/WebPart/ECommerce/Products/AjaxProductBackend.ashx?cmd=17&beginlevel=2&pageid='+pageId+'&pageiddetailproduct='+detaiId+'&template=/Template/Menu/MenuCatalogue.html&t='+ new Date().getTime();	
	$.ajax({
		type: "GET",
		url: urlremote,             
		success: function(msg){
			if (msg.length > 0){
				if($(id).size() > 0){
					$(id).append(msg);				
					$(".listcategory_item",id).each(function(){
						$(".cattitle a",this).html("<img src='"+$(".cattitle",this).attr("rel1")+"'/>");
					});
					$("li",id).hover(function(){
						$(this).addClass("hover");
					},function(){
						$(this).removeClass("hover");
					});
				}
				mainmenu()
			}			
		}
    });
}
var contentDetaiProduct = function(){
	if($(".ProductContainer").size() > 0){
		loadscroll(".product_Content");
	}
	imgColor(".ColorSP .changeColor",".ColorSP .bigImgColor img");
	productGallery();
	lineTableEvenOdd();
	$(".Content_Panel .product_Content").append("<span class='IconClosePanel'></span>");		
	$(".Content_Panel .IconClosePanel").click(function(){
		$(".Content_Panel").animate({top:'-2000px'},1);
		$(".menu li a").removeClass("active");
	});	
	$(".menu li a").click(function(){
		$(".menu li a").removeClass("active");
		if($(this).attr('href') != undefined && $(this).attr('href') != ""){return true;}
		else{
			$(".Content_Panel").stop().animate({top:'-2000px'},1000);
			var id = $(this).attr('rel');
			if(parseInt($(id).css('top')) < -999){
				$(id).stop().animate({top:'-423px'},500);
				$(this).addClass("active");
			}
			else{
				$(id).animate({top:'-2000px'});
			}
		}		
	});		
}
var fixJs = function(){
	if($(".NewYear .webpart").size() > 0){
		$(".NewYear .closed").show();
		$(".NewYear .closed").click(function(){
			$(".NewYear").fadeOut(500);
		});
	}
}
var loadscroll = function(selector){	
	$(selector).jScrollPane({
		scrollbarWidth:10, 
		scrollbarMargin:10, 
		animateScroll :false,
		verticalDragMinHeight :19,
		verticalDragMaxHeight :19,
		showArrows:false
	});
}
var imgColor = function(objID,objImg){
	if($(".ColorSP .listItems li").size() >= 6){
		$(".ColorSP .listColor a[class!='changeColor']").show();
	}
	digip.recall('jCarouselLite', '.ColorSP .listItems', {
		visible:6,
		speed:100,
		btnNext:'.ColorSP .next',
		btnPrev:'.ColorSP .prev'
	},function(){
		$(objImg).attr("src",$(objID).eq(6).attr('rel'));
		$(objID).click(function(){
			$(objImg).attr("src",$(this).attr('rel'));
		});
	});		
}
var productGallery = function(){
	digip.recall('jCarouselLite', '.Gallery_Panel .scroll', {
		visible: 3,
		vertical:true,
		btnNext: '.Gallery_Panel .next',
		btnPrev: '.Gallery_Panel .prev'
	});	
	digip.recall('fancybox', 'a[rel=detailProduct]',{
		'transitionIn' : 'none',
		'transitionOut' : 'none',
		'titlePosition' : 'over',
		'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
		}
	}); 
}

var lineTableEvenOdd = function(){
	$("table tr:even").addClass("even");$("table tr:odd").addClass("odd");
}
var PopupGalleryPhoto = function(){	
	$("a.photoClick").fancybox({
		autoScale:true,
		autoDimensions:true,
		centerOnScroll:true,
		type:'ajax',
		onComplete:function(){$(this).resize();}
	});	
}
var SlidePhoto = function(){
	digip.recall('cycle', '.fordGallery ul',{
		speed:  '1000', 
		timeout:0,
		next: '.fordGallery .next',
		prev: '.fordGallery .prev',
		befor:function(){
			var title = $("a",this).attr('title');
			$(".fordGallery .gTitle").html(title);
		},
		after:function(){			
			var title = $("a",this).attr('title');
			$(".fordGallery .gTitle").html(title);
		}
	});
}
var binHeightContent = function(){
	if($("#Main-Default").size() > 0){
		var _h = $("#Main-Default .wrapContent").height();
		if(_h < 430){
			$("#Main-Default .wrapContent").height(430);
		}
	}
}
var untilDetail = function(){	
/*------------------------------------------- Print -------------------------------------------------------------------*/	
	digip.recall('jprintnow', '.print a', {target:".jPrint",cssbonus:'body{background:#fff;}.jPrint{width:800px;margin:auto;}'});	
/*------------------------------------------- Send Mail ---------------------------------------------------------------*/	
	$('a.thickbox_sendmail').fancybox({});
/*------------------------------------------- light box ---------------------------------------------------------------*/	
	digip.recall('lightbox', '.lightbox', {});
}
