$(document).ready(function() {

	$(".col-left > ul > li > ul.productmenu > li").mouseover(function(){
		$(this).addClass('triggerdrop');
	});

	$(".col-left > ul > li > ul.productmenu > li").mouseout(function(){
		$(this).removeClass('triggerdrop');
	});

	/*
	$(".product-detail-left-image").mouseover(function(){
		$(this).addClass('product-detail-left-image-hover');
		$(".product-detail-left-image table.top-table").css('top','50px');
		$(".product-detail-left-image table.bottom-table").css('bottom','44px');
	});

	$(".product-detail-left-image").mouseout(function(){
		$(this).removeClass('product-detail-left-image-hover');
		$(".product-detail-left-image table.top-table").css('top','0');
		$(".product-detail-left-image table.bottom-table").css('bottom','0');
	});
	*/

	$('.product-detail-left-image:not(.product-detail-left-image-icons)').mouseover(
		function() {
			$(this).addClass('product-detail-left-image-hover');
			$(this).find("table.top-table").css('top','50px');
		}
	);
	$('.product-detail-left-image:not(.product-detail-left-image-icons)').mouseout(
		function() {
			$(this).removeClass('product-detail-left-image-hover');
			$(this).find("table.top-table").css('top','0');
		}
	);



	/*
	$('.product-detail-left-image-icons img').mouseover(
		function() {
			$(this).next('table').show().css('bottom','20px');
		});
		$('.product-detail-left-image-icons img').mouseout(
		function() {
			$(this).next('table').hide().css('bottom','0');
		}
	);

		$('.product-detail-left-image-icons .bottom-table').mouseover(
				function() {
					$(this).next('table').show().css('bottom','20px');
				});
				$('.product-detail-left-image-icons .bottom-table').mouseout(
				function() {
					$(this).next('table').hide().css('bottom','0');
				}
			);
	*/
	$('div.seal').hover(function() {
			$(this).find('table').show().css('bottom','40px');
			$(this).find('table').show().css('left','30px');

		},
		function() {
			$(this).find('table').hide().css('bottom','0');
		}
	);



	$(".flag-dropdown .middle .gradient-left table td a").mouseover(function(){
		$(this).css('background-image', 'url('+$(this).attr('rel')+')');
	});
	$(".flag-dropdown .middle .gradient-left table td a").mouseout(function(){
		$(this).css('background-image', 'url('+$(this).attr('longdesc')+')');
	});
/*
	$(".langs a.first").click(function(){
		$(this.parentNode).addClass('trigger');
	});
	$('.langs').mouseout(function() {
		$(".langs li:first").removeClass('trigger');
	});
*/
	$('.langs').langMenu();

	/*** Extensions ****/
	$("#subproduct").change(function(e){
		//alert('change subproduct');
		var val = $(this).val();
		if(val != '-1') {
			window.location.href = '/'+val;
		}
		//$(this).parent('form').submit();
	});

	$('select.filterable').change(function() {
		$('#currentPageCounter').val( 0 );
		updateKriteriaForm();
	});
	$('a.paginator').live('click',function(e) {
		e.preventDefault();
		var page = $(this).attr('href').split('#').pop();
		$('#currentPageCounter').val( page );
		updateKriteriaForm();
	});

	/*** Replace Flags in Lang Sitemap ***/
	$('.sitemap-col_larger li img').each(function() {
		var fileName = $(this).attr('src');
		$(this).attr('src',fileName.replace('.png', '_hover.png').replace('uploads/media/','fileadmin/templates/img/flags/'));
	});

	function updateKriteriaForm() {
		var $form = $('form.kriteria-form');
		var $loader = $('#loading');
		$loader.removeClass('hidden');
		$('div#pi2-results').load($form.attr('action') + ' div#pi2-results',$form.serialize(),function() { $loader.addClass('hidden'); });
	}

	$('.drop-shadow img').hover(
		function() { $(this).dropShadow( {left: 6, top: 4, blur: 5, opacity : 1} );},
		function() { $(this).removeShadow(); }
	);

	/* unocomment this if you want to hide flagdropdown by click on any flag link */
	/*$(".langs li:first table td a").click(function(){
		$(".langs li:first").removeClass('trigger');
	});*/


    /*$('.langs a.first').blur(function() {
        $(".langs li:first").removeClass('trigger');
    	});*/
//.langs li .flag-dropdown

});

jQuery.fn.langMenu = function() {
	var ulHover = false;
	var tableHover = false;
	var $trigger;

	$trigger = this.find('li:first');

	function showLangs () { $trigger.addClass('trigger'); };
	function hideLangs () {
		if(!ulHover && !tableHover )
			$trigger.removeClass('trigger');
	};

	//Show on click
	this.find("a.first").click(function(){
		showLangs();
	});

	//Hover the table
	this.find('.flag-dropdown').hover(
		function() { tableHover = true; },
		function() { tableHover = false; hideLangs(); }
	);

	//Hover the UL
	this.hover(
		function() { ulHover = true; },
		function() { ulHover = false; hideLangs();}
	);
}

