var recommendedId = null;
$(document).ready(function(){	 
						   
/* ------------------------------------------------------------------------------------------------------------- */	
$("ul li:first-child, ol li:first-child").addClass("first");
$("ul li:last, ol li:last").addClass("last");
$("tbody tr:odd, ul li:odd, ol li:odd").addClass('odd');
$("tbody tr:even, ul li:even, ol li:even").addClass('even');
/* ------------------------------------------------------------------------------------------------------------- */	
$("table tr.odd").hover(function(){
	$(this).addClass('oddhover');
  }, function(){
	$(this).removeClass('oddhover');
  }
);
$("table tr.even").hover(function(){
	$(this).addClass('evenhover');
  }, function(){
	$(this).removeClass('evenhover');
  }
);
/* ------------------------------------------------------------------------------------------------------------- */	
$('input.text, input.search, textarea, select').click(function(){	
	$(this).addClass('focus');
}).focus(function(){	
	$(this).addClass('focus');
}).blur(function(){	
	$(this).removeClass('focus');
});	
$('#headerSearch form.search').mouseover(function(){	
	$('#headerSearch form.search fieldset.option').addClass('optionBlock');
}).mouseleave(function(){
	$('#headerSearch form.search fieldset.option').removeClass('optionBlock');
});
/* ------------------------------------------------------------------------------------------------------------- */	
// toolbar-menu	
	$("#toolbar-menu ul.menu li.menu").mouseover(function(){
		$(this).addClass("hover");
	}).mouseleave(function(){
		$(this).removeClass("hover");
	});
	
	
	$("#headerMark ul li.settings").mouseover(function(){
		$(this).addClass("hover").addClass('noborder').next('li').addClass('noborder');
	}).mouseleave(function(){
		$(this).removeClass("hover").removeClass('noborder').next('li').removeClass('noborder');
	});	
	
/*
		var $tmp_width = $('#toolbar-menu ul.menu li.menu strong a.menu').width();
		alert ($tmp_width);
		$tmp_width = ($tmp_width/2)-16;
		$('#toolbar-menu ul.menu li.menu strong a.menu span.arrow').css('left',$tmp_width);
*/
// end toolbar-menu

// admin-menu
	$("#admin-menu").mouseover(function(){	
		$(this).find('div.container').css('display', 'block');
	}).mouseleave(function(){
		$(this).find('div.container').css('display', 'none');
	});
// end admin-menu

// shopProduct
	$("div.shop div.shopProduct dl dd a.photo").mouseover(function(){	
		$(this).parent().find('div.viewProduct').css('display', 'block');															
		return false;
	}).mouseleave(function(){
		$(this).parent().find('div.viewProduct').css('display', 'none');
		return false;
	});	
// end shopProduct


// zIndex

	var zIndexNumber = 500;
	$('.zIndex').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 1;
	});
	
// end zIndex

// icoPromotion

	//$('div.icoPromotion div.icoDescription').hide();
	
// end icoPromotion
	
	  

// rotateRecommended
	var idBoxRecommended = $("#boxRecommended ul.tabs-nav li").length;
	var idBoxRecommended1 = idBoxRecommended + 1
	var rotateTime = 6000;
	var rotateTimeInterval = 18000;
	if (idBoxRecommended > 1) {
		function rotateRecommended() {
			var current = parseInt($('#boxRecommended ul.tabs-nav li.active').text());
			var next = (current + 1) % idBoxRecommended1;
			if (0 == next) {
				next += 1;
			}
			$('#boxRecommended ul.tabs-nav li').removeClass('active');
			$('.recommended' + next).addClass('active');
			$('div.recommended' + next).css("display","block");
			$('div.recommended' + current).css("display","none");
			window.clearInterval(recommendedId);
			recommendedId = window.setInterval(rotateRecommended, rotateTime);		
		}
		
			recommendedId = window.setInterval(rotateRecommended, rotateTime);
		
		$('#boxRecommended ul.tabs-nav li').click(function () {
			window.clearInterval(recommendedId);
			recommendedId = window.setInterval(rotateRecommended, rotateTimeInterval);
			var current = parseInt($(this).text());
			$('#boxRecommended ul.tabs-nav li').removeClass('active');
			$(this).addClass('active');
			$('div.recommended').css("display","none");
			$('div.recommended' + current).css("display","block");
			return false;
		});
	} else {
		$('#boxRecommended ul.tabs-nav li').css("display","none");
	};
// end rotateRecommended

// --- toplayer --------------------------------------------------------------	
	var toplayerWidth = $("#toplayer").width();
    $("#toplayer").css("marginLeft",-toplayerWidth/2).append('<div class="close"></div>');
	$("#toplayer .close").click(function () {
		$("#toplayer").remove();
		return false;
	});
	$("#toplayer .close").click(function () {
		$("#toplayer").remove();
		return false;
	});	
	var toplayerTime = 16000;
	function rotateToplayer() {
		$("#toplayer").remove();
		return false;		
	}
	toplayerId = window.setInterval(rotateToplayer, toplayerTime);
	
	$(document).keyup(function(event){
		if (event.keyCode == 27) {
			$("#toplayer").remove();
			return false;	
		}
	});
// --- end toplayer --------------------------------------------------------------	
	
	

    $("#content div.content div.bbgallery").attr("id", function (arr) {										  
		return "bbgalleryId" + arr; 
	});
	$('#content div.content div.bbgallery').each(function() {
		var bbgallery = $('#'+ this.id).find("div:first").addClass(this.id).attr("class");
		if (bbgallery.indexOf("img-left")==0) {
			 $('#'+this.id).addClass("bbgallery-left");
		} else if (bbgallery.indexOf("img-right")==0) {
			$('#'+this.id).addClass("bbgallery-right");
		};
	});	

	$(".bbwidthorg img").load(function(){
		$(".bbwidthorg").attr("id", function (arr) {										  
			return "bbwidthorgId" + arr; 
		});
		$('.bbwidthorg').each(function() {					   
			var widthImg = $('#'+this.id+' img').width();
			$('#'+this.id).width(widthImg+32);
		});
	});

});	
