$(function(){
    $("#gadget_1").each(function(){
	$(this).hover(function(){
		$(this).animate({width: "250px"}, {queue:false, duration:450});
      },function() {
		  $(this).animate({width: "30px"}, {queue:false, duration:450});
	  });
    });
});

$(function(){
    $("#gadget_2").each(function(){
	$(this).hover(function(){
		$(this).animate({width: "250px"}, {queue:false, duration:450});
      },function() {
		  $(this).animate({width: "30px"}, {queue:false, duration:450});
	  });
    });
});

$(document).ready(function(){
	if($.browser.webkit || $.browser.opera) {
		$('.MagicSlideshow img').attr('alt','');
	}
	$('#login_link').bind('click',function() {
		$('#footer_left div.textcontent>div').hide();
		$('.fb_like').hide();
		$('#user_login_form').show();
		$('#user_login_form #input_email').focus();
	});
	$('#login_back').bind('click',function() {
		$('#user_login_form').hide();
		$('.fb_like').show();
		$('#footer_left div.textcontent>div').show();
	});
	$('#user_login_form').click(function(e) {
		if (e.target !== this) {
			return;
		}
		$(this).hide();
		$('.fb_like').show();
		$('#footer_left div.textcontent>div').show();
	});
	$('#user_login_form').keypress(function(e) {
		if(e.which == 13) {
			if($('#input_email').val() != '' && $('#input_password').val() != '') {
				$('#form_shop_login').submit();
			}
		}
	});
	$('#login_send').bind('click',function() {
		$('#form_shop_login').submit();
	});
	$(document).keypress(function(event) {
		if (event.keyCode == 27) {
			$(this).trigger('escapeKey');
		}
	});
	$(document).bind('escapeKey', function(event) {
		if ($('#user_login_form').is(':visible')) {
			$('#user_login_form').hide();
		} else if ($('#consultation_mask').is(':visible')) {
			$('#consultation_mask').hide();
		}
	});
	$('.slide_content').hide().end();
	$('.slide_header').click(function() {
		var currClass = $(this).attr('class').split(' ')[0];
		$(this).toggleClass(currClass + '_open');
		$(this).next().slideToggle('slow');
	});
	$('#script_disabled').remove();
	$('#menu_1 li.level_1').mouseenter(function() {
		$(this).find('.level_2_frame').stop(true,true).fadeIn("100");
	});
	$('#menu_1 li.level_1').mouseleave(function() {
		$(this).find('.level_2_frame').hide();
	});
	$('#item_title').hide();
	$('.item_main_image_layer1>a>img').bind("load",function(){
		$('#item_title').fadeIn(1500);
	});
	$('#spinner_minus').bind("click",spinnerDown);
	$('#spinner_plus').bind("click",spinnerUp);
	$('#order_item_text').bind("click",orderFormSend);
	$('#consultation').bind("click",function(){
		$('.fb_like').hide();
		$('#footer_left div.textcontent>div').hide();
		$('#consultation_mask').show();
	});
	$('#consult_form').bind("change",function() {
		$('#consultation_bottom').toggle();
	});
	$('#basketimage').bind("click",orderFormSend);
	$('#consultation_back').bind("click",function(){
		$('#consultation_mask').hide();
		$('.fb_like').show();
		$('#footer_left div.textcontent>div').show();
	});
	$('#consultation_mask').click(function(e) {
		if (e.target !== this) { return; }
		$(this).hide();
		$('.fb_like').show();
		$('#footer_left div.textcontent>div').show();		
	});
	$('div.itemlist3').mouseenter(function(){
		$(this).find('div.itemlist3_overlay').stop(true,true).fadeIn();
	});
	$('div.itemlist3').mouseleave(function(){
		$(this).find('div.itemlist3_overlay').fadeOut();
	});
	$('.basket_line').mouseenter(function() {
		$(this).find('img.basket_remove').attr('src','/layout/frontend/enduser/img/remove_from_basket_hover.gif');
	});
	$('.basket_line').mouseleave(function() {
		$(this).find('img.basket_remove').attr('src','/layout/frontend/enduser/img/remove_from_basket.gif');
	});
	$('.basket_img_tag>img').load(function(){
		var basketImg = $(this);
		var imgHeight = parseInt(basketImg.height());
		var imgMargin = (120 - imgHeight) / 2;
		if (imgMargin > 0) {
			basketImg.css('margin-top',imgMargin + 'px');
			basketImg.css('margin-top',imgMargin + 'px');
		}
	});
	var basketImg = $('.basket_availability>div');
	var basketAmnt = $('.basket_input>div.dspl_item_qtty');
	var imgHeight = parseInt(basketImg.height());
	var amntHeight = parseInt(basketAmnt.height());
	var imgMargin = (120 - imgHeight) / 2;
	var amntMargin = (120 - amntHeight) / 2;
	if (imgMargin > 0) {
		basketImg.css('margin-top',imgMargin + 'px');
		basketImg.css('margin-top',imgMargin + 'px');
	}
	if (amntMargin > 0) {
		basketAmnt.css('margin-top',amntMargin + 'px');
		basketAmnt.css('margin-top',amntMargin + 'px');
	}
	$('div.item_images>a>img').load(function(){
		var parentA = $(this).parent();
		var imgHeight = parseInt($(this).height());
		var imgWidth = parseInt($(this).width());
		var horzMargin = (150 - imgWidth) / 2;
		var vertMargin = (140 - imgHeight) / 2;
		if (horzMargin > 0) {
			$(this).css('margin-right',horzMargin + 'px');
			$(this).css('margin-left',horzMargin + 'px');
		}
		if (vertMargin > 0) {
			$(this).css('margin-top',vertMargin + 'px');
			$(this).css('margin-bottom',vertMargin + 'px');
		}
	});
	$('a.itemlist3_link>img').load(function(){
		var imgHeight = parseInt($(this).height());
		var imgWidth = parseInt($(this).width());
		var horzMargin = (100 - imgWidth) / 2;
		var vertMargin = (100 - imgHeight) / 2;
		if (horzMargin > 0) {
			$(this).css('margin-right',horzMargin + 'px');
			$(this).css('margin-left',horzMargin + 'px');
		}
		if (vertMargin > 0) {
			$(this).css('margin-top',vertMargin + 'px');
			$(this).css('margin-bottom',vertMargin + 'px');
		}
	});
	$('.itemlist2_image_layer1>img').load(function(){
		var parentA = $(this).parent();
		var imgHeight = parseInt($(this).height());
		var imgWidth = parseInt($(this).width());
		var horzMargin = (180 - imgWidth) / 2;
		var vertMargin = (145 - imgHeight) / 2;
		if (horzMargin > 0) {
			$(this).css('margin-right',horzMargin + 'px');
			$(this).css('margin-left',horzMargin + 'px');
		}
		if (vertMargin > 0) {
			$(this).css('margin-top',vertMargin + 'px');
			$(this).css('margin-bottom',vertMargin + 'px');
		}
	});
	var targetDiv = $('div.basket_item_desc>div');
	var elementHeight = parseInt(targetDiv.height());
	var vertMargin = (120 - elementHeight) / 2;
	if (vertMargin > 0) {
		$(targetDiv).css('margin-top',vertMargin + 'px');
		$(targetDiv).css('margin-bottom',vertMargin + 'px');
	}
	var targetDiv = $('div.basket_availability>a');
	var elementHeight = parseInt(targetDiv.height());
	var vertMargin = (120 - elementHeight) / 2;
	if (vertMargin > 0) {
		$(targetDiv).css('margin-top',vertMargin + 'px');
		$(targetDiv).css('margin-bottom',vertMargin + 'px');
	}

	var targetDiv = $('div.basket_availability>a')
	var imgHeight = parseInt(targetDiv.height());
	var vertMargin = (120 - imgHeight) / 2;
	if (vertMargin > 0) {
		$(targetDiv).css('margin-top',vertMargin + 'px');
		$(targetDiv).css('margin-bottom',vertMargin + 'px');
	}

	$('#payment_options>span').bind('click',function() {
		window.location = "http://birdie-lounge.dc-solution.de/zahlungsmittel/";
	});
	
	$("div.itemlist2").each(function (i) {
		if ($(this).data("tooltip") != "") {
			var tooltipId = $(this).data("tooltip");
			$(this).bind("mouseenter", function() {
				var target = document.getElementById(tooltipId);
				$(target).stop(true,true).fadeIn('slow');
			});
			$(this).bind('mouseleave', function() {
				var target = document.getElementById(tooltipId);
				$(target).stop(true,true).fadeOut('slow');
			});
		};	
	});
});


function spinnerUp() {
	var inputVal = parseInt($('#input_item_quantity').val());
	var newVal = inputVal + 1;
	if (newVal < 100 && newVal > 0){
		$('#input_item_quantity').val(newVal);
	}
}

function spinnerDown() {
	var inputVal = parseInt($('#input_item_quantity').val());
	var newVal = inputVal - 1;
	if (newVal < 100 && newVal > 0){
		$('#input_item_quantity').val(newVal);
	}
}

function orderFormSend() {
	$('#form_itemcard').submit();	
}

function showDescLayer(divId) {
	$('.show').removeClass('show').addClass('hide');
	var target = "#" + divId;
	$(target).removeClass('hide').removeClass('show').addClass('show');
}

function showDescTab (tab)  {
	$('.tabon').removeClass('tabon').addClass('taboff');
	var target = "#" + tab;
	$(target).removeClass('taboff').removeClass('tabon').addClass('tabon');
}



