$(document).ready(function(){
	$('a, img').click(function(){
		$('a').blur();
	});
	
	$(".module-categories ul li").click(function(){
		$(".module-categories ul li ul").hide();
		$(this).children("ul").show();
	});
	
	$(".module-categories ul li img.changeimage").click(function(){
	
		$(".module-categories ul li img.actived").each(function(i){
			$(this).attr('class','changeimage');
			var img_src = $(this).attr('src');
			img_ext = img_src.split(".")[1];			
			img_src = img_src.split("_over.")[0];
			img_src += "." + img_ext;
			$(this).attr('src',img_src);
			
			$(this).attr('class','changeimage');
		});
				
		$(this).addClass('actived');
		$(this).removeClass('changeimage');					
		var img_src = $(this).attr('src');
		img_ext = img_src.split(".")[1];
		img_src = img_src.split(".")[0];		
		img_src += "." + img_ext;
		$(this).attr('src',img_src);	
		
	});
	
	$('.module-categories ul.top li img.changeimage').hover(
		function(){
		$(this).css('cursor','pointer');		
		var img_src = $(this).attr('src');
		var img_ext = img_src.split(".")[1];		
		var img_over = img_src.indexOf("_over.");
		
		if(img_over < 0){
			img_over = img_src.split('.')[0];
			img_over += "_over." + img_ext;			
			$(this).attr('src',img_over);
			return;
		}	
	},
		function(){
		var actived = $(this).attr('class');		
		actived = actived.indexOf("actived");
		if(actived >= 0){
			return;
		}
		var img_src = $(this).attr('src');	
		img_ext = img_src.split("_over.")[1];	
		img_src = img_src.split("_over.")[0];		
		img_src += "." +img_ext;
		$(this).attr('src',img_src);
		$(this).attr('class','changeimage');
		}
	);
	
	//Xu ly Shopping Cart Button
	$('div.shopping-cart-tools .continue-shopping').click(function(){
		window.location = '/funcoolo/store/category/men';
	});
	
	$('div.shopping-cart-tools .checkout').click(function(){
		window.location = '/funcoolo/store/checkout';
	});
	
	
	//Validate form product detail and add to cart. Must choice a size to submit	
	
});

function over(id,img){
	id.src= "./images/" + img+"_over.png";
}

function out(id,img){
	id.src="./images/" + img+".png";
}

function changeimage(classname){
	var aimg = document.getElementsByTagName("img");
	for (var i in aimg){
		if (aimg[i].className == classname){
			aimg[i].name = aimg[i].src.split('.')[0];
			aimg[i].onmouseover = function() {
				this.src = this.name + "_over.gif";
			}
			aimg[i].onmouseout = function() {
				this.src = this.name + ".gif";
			}

		} 
	}
}

function imageover(){
	
	var aimg = document.getElementsByTagName("img");
	for (var i in aimg){
		if (aimg[i].className == 'imgover' || aimg[i].className == 'imgnormal'){
		
			aimg[i].onmouseover = function() {
				this.className='imgover';
			}
			aimg[i].onmouseout = function() {
				this.className='imgnormal';
				
			}

		} 
	}
}
