$(document).ready(function() {

	$(document).pngFix();

    $('.headerblocks li.block1').hover(function() {
		if (!($(this).hasClass('block1-active'))) $(this).addClass('block1-active');
    }, function() {
		if (($(this).hasClass('block1-active'))) $(this).removeClass('block1-active');
	});

    $('.headerblocks li.block2').hover(function() {
		if (!($(this).hasClass('block2-active'))) $(this).addClass('block2-active');
    }, function() {
		if (($(this).hasClass('block2-active'))) $(this).removeClass('block2-active');
	});

    $('.headerblocks li.block3').hover(function() {
		if (!($(this).hasClass('block3-active'))) $(this).addClass('block3-active');
    }, function() {
		if (($(this).hasClass('block3-active'))) $(this).removeClass('block3-active');
	});

	var ACTIVE_BRAND = null;
	var WE_ON_MENU = null;
	var ACTIVE_MENU_SLIDESHOW = 0;
	var TOP_MENUS = ['gucci', 'vuitton', 'prada', 'chanel'];

	function hideActiveNavs(){
		$('.labelsnav li a').each(function(){
			var img = $(this).children().attr('src');
			if (img.substr(img.length-10) == 'active.png') {
				var width = $(this).parent().attr('width');
				$(this).html('<img width="'+width+'" src="' + img.substr(0, img.length-10) + '.png" />').pngFix();
			}
		});
	}

	function setMenuElementActive(o){

		var itemname = $(o).children().children().attr('src');
		if (itemname.substr(itemname.length-10) != 'active.png') {
			hideActiveNavs();
			var width = $(o).attr('width');
			$(o).children().html('<img width="'+width+'" src="' + itemname.substr(0, itemname.length-4) + 'active.png"  />').pngFix();

			ACTIVE_BRAND = $(o).attr('brand');
			$('div.headerlabel:visible').fadeOut();
			$('div.headerlabel.' + $(o).attr('brand')).fadeIn('normal');

			for( var i in TOP_MENUS ){
				if ( TOP_MENUS[i] == ACTIVE_BRAND ){
					ACTIVE_MENU_SLIDESHOW = i;
				}
			}

			}
	}

	function setMenuElementInActive(o){
    	hideActiveNavs();
    	var imgPlacer = $('div.labelsnav li[brand='+ACTIVE_BRAND+']').children();
    	var imgSrc = imgPlacer.children().attr('src');
    	var width = $(o).attr('width');

    	imgPlacer.html('<img width="'+width+'" src="' + imgSrc.substr(0, imgSrc.length-4) + 'active.png"  />').pngFix();

	}
	
	
    
    $('.labelsnav li').hover(function() {	
    	setMenuElementActive(this);
    	WE_ON_MENU = true;
		}, 
    function() {
    	setMenuElementInActive(this);
    	WE_ON_MENU = false;
	  });	


	/*
	if ( typeof SHOP_SLIDER_DISABLED == 'undefined')  {
	  setInterval(function(){
	  	if ( !WE_ON_MENU ) {
	  		var li = ('div.labelsnav li[brand='+TOP_MENUS[ACTIVE_MENU_SLIDESHOW]+']');
	  		setMenuElementActive(li);
	  		ACTIVE_MENU_SLIDESHOW++;

	  		if (ACTIVE_MENU_SLIDESHOW > 3){
	  			ACTIVE_MENU_SLIDESHOW = 0;
	  		}
	  	}
	  }, 5000);
	}
	*/


    
    $('.hccheckout').hover(function() {
		$(this).css('background-color', '#666');
    }, function() {
		$(this).css('background-color', '#999');
	});

    $('.lmlist li').hover(function() {
		$(this).css('background-color', '#efc8c1');
    }, function() {
		$(this).css('background-color', '#ece4dc');
	});
	
    $('.hcsbutton a').hover(function() {
		$(this).children().attr('src', '/templates/img/searchbuttononn.jpg');
    }, function() {
		$(this).children().attr('src', '/templates/img/searchbutton.jpg');
	});
	
    $('.lmlistheader li').click(function() {
		$(this).parent().children('li').removeClass('active');
		$(this).addClass('active');
		var curid = $(this).attr('id');
		if (curid == 'shoes') {
			$('#lmlisthandbags').addClass('hidden');
			$('#lmlistshoes').removeClass('hidden');
		} else {
			$('#lmlisthandbags').removeClass('hidden');
			$('#lmlistshoes').addClass('hidden');
		}
	});

    $('ul.cataloglist li .icon').hover(function() {
		$(this).css('background-position', '0px -17px');
    }, function() {
		$(this).css('background-position', '0px 0px');
	});

    $('ul.cataloglist.contentblock li .icon').hover(function() {
			if ( !$(this).hasClass('nochange') ) {
				$(this).css('background-position', '0px 0px');
			}
    }, function() {
    	if ( !$(this).hasClass('nochange') ) {
				$(this).css('background-position', '0px -34px');
			}
	});
	
    $('ul.cllist li').hover(function() {
		$(this).css('background-color', '#e7e7e7');
		$(this).children('.info').children('.icon').css('background-position', '0px -17px');
    }, function() {
		$(this).css('background-color', '#fff');
		$(this).children('.info').children('.icon').css('background-position', '0px 0px');
	});

    $('.baskettable table tr').hover(function() {
		if (!$(this).hasClass('active')) {
			$(this).addClass('active');
		}
    }, function() {
		if ($(this).hasClass('active')) {
			$(this).removeClass('active');
		}
	});
		
	$('.linkbigpreview a').click(function() {
		if ($('.productbigpreview').hasClass('hidden')) {
			$('.cpdparameters select').hide();
			$('.productbigpreview').removeClass('hidden');
		} else {
			$('.cpdparameters select').show();
			$('.productbigpreview').addClass('hidden');
		}
		return false;
	});
	
    $('.productsmallpreview img').hover(function() {
		$(this).css('border-color', '#f33');
    }, function() {
		$(this).css('border-color', '#999');
	});
	
	$('.cpdmenu ul li a').click(function() {
		if (!$(this).parent().hasClass('active') && !$(this).parent().hasClass('first-active') && !$(this).parent().hasClass('first')) {
			$(this).parent().parent().children('li.first-active').removeClass('first-active').addClass('first');
			$(this).parent().parent().children('li.active').removeClass('active');
			$(this).parent().addClass('active');			
		}
		if (!$(this).parent().hasClass('active') && !$(this).parent().hasClass('first-active') && $(this).parent().hasClass('first')) {
			$(this).parent().parent().children('li.active').removeClass('active');
			$(this).parent().removeClass('first').addClass('first-active');
		}
		return false;
	});




	$('ul.lmlistother a.menu_handler').click(function(){
		//hide old active
		if ( !$(this.parentNode).hasClass('active') ) {
			$('ul.lmlistother li.active ul').hide('normal');
			$('ul.lmlistother li.active').removeClass('active');
		}
		
		var o = $(this).parent().find('ul:first');
		var menu_id = o.attr('id');

		o.toggle('normal'); 
		$(this.parentNode).toggleClass('active'); 
		if ($.cookie('menu_opened') == menu_id){
			$.cookie('menu_opened', 'null', {path: '/'});
		}
		else {
			$.cookie('menu_opened', menu_id, {path: '/'}); 
		}
		return false;
	});

	
});

