
$(function() {
	// general settings for the modalwindow
	var settings = {
		css : {
			wrapper : {
				top : '45%',
				border : '4px solid #fff'
			},
			loading : {
				top : '45%'
			}
		},
		closeButton: '',
		minHeight : 150
	};
	$.nyroModalSettings(settings);

    $('.product-holder, .product-holder-full').each(function(){
		if($('#tooltip-'+$(this).attr('id')).length > 0){
			$(this).bt(
				{
					contentSelector: "$('#tooltip-'+$(this).attr('id')).html();",
					fill: '#fffcdb',
					positions: 'top',
					cornerRadius: 0,
					strokeWidth: 0,
					hoverIntentOpts:  {
						interval: 1,
						timeout: 1
					}
				}
			);
		}
	});

    $('div.primary-content a[title!=""]').bt(
        {
            fill: '#fffcdb',
            positions: 'top',
            cornerRadius: 0,
            strokeWidth: 0,
            hoverIntentOpts:  {
                interval: 1,
                timeout: 1
            }
        }
    );

    $('.make-list li[title!=""]').bt(
        {
            fill: '#fffcdb',
            positions: 'top',
            cornerRadius: 0,
            strokeWidth: 0,
            hoverIntentOpts:  {
                interval: 1,
                timeout: 1
            }
        }
    );

     $('.store-category-label[title!=""]').bt(
        {
            fill: '#fffcdb',
            positions: 'top',
            cornerRadius: 0,
            strokeWidth: 0,
            hoverIntentOpts:  {
                interval: 1,
                timeout: 1
            }
        }
    );

    $('.disable-poster').addClass('display-none-element');
    $('.enable-poster').removeClass();

    $('.map li').click(function() {
        show_tab(this);
        return false;
    });

    $('#storfinder_left, #storefinder_zipcode').focus(function(){
		$(this).attr('value', '');
	}).keyup(function(){
		// replace st. -> sankt
		if($(this).val() == 'st.' || $(this).val() == 'St.'){
			$(this).val('Sankt ');
		}
		// replace all double whitespace
		$(this).val($(this).val().replace('  ', ' '));
	});


    $('.side-box-c').blur(function(){
		$(this).attr('value', $('#SearchField').attr('searchtext'));
	  });
	$('#SearchField').focus(function(){
		$(this).attr('value', '');
	});








	$(".navigation li").hover(
        function() {
            var navitem = $(this).find(".navigation-top-img");
            $(navitem).attr({ 'src': navitem.attr("hover")});
			$(this).addClass('hover');
        },
		function(){

		}
    ).bind('mouseleave',
        function() {
            var navitem = $(this).find(".navigation-top-img");
            $(navitem).attr({ 'src': navitem.attr("set")});
			$(this).removeClass('hover');
        }
    );

	$(".button").hover(
        function() { $(this).attr({ 'src': $(this).attr("hover")});}
    ).bind('mouseleave',
        function() { $(this).attr({ 'src': $(this).attr("set")});}
    );

    $(".extra-boxes li").click(function () {
        window.location = $(this).attr('url');
    });

	$(".flyerLink").click(function(){
		var flashfile = $(this).attr('flashfile');
		var flyerid = $(this).attr('nodeId');
		var domain = $(this).attr('domain');
		var site_access_name = $(this).attr('site_access_name');
		var site_access_type = $(this).attr('site_access_type');
		showFlyer(flashfile, flyerid, domain, site_access_name, site_access_type);
		return false;
	});

	$(".voucher-print-button").click(function(){
		printWindow($(this).attr('href'), $(this).attr('title'));
		return false;
	});

	$(".tipReadMore").click(function(e){
		e.preventDefault();
		var url = "/ajax/tips?NodeId=" + $(this).attr("tipNodeId");

		if(jQuery.browser.msie){
			$.nyroModalManual({
				url : url,
				closeButton : '',
				css: {
					wrapper: { top: '50%', border: 'none', 'overflow-x': 'hidden', 'overflow-y': 'auto'},
					loading: { top: '50%'},
					content: { 'overflow-x': 'hidden', 'overflow-y': 'auto', height: 'auto'}
					},
				endShowContent : function(){
					$('a[href^="#"], a[href*="#"]').live('click',(function(){
						$('.tip_detail').scrollTo( 'a[name="' + $(this).attr('href').replace('#', '').replace(document.URL, '') +'"]', 1500, { easing:'swing', queue:true, axis:'xy', margin:true, offset:-50 } );
						return true;
					}));
				}
			});
		} else {
			$.nyroModalManual({
				url : url,
				closeButton : '',
				css: {
					wrapper: { top: '50%', border: 'none'},
					loading: { top: '50%'},
					content: { 'overflow-x': 'hidden', 'overflow-y': 'auto',width:'620px'}
					},
				endShowContent : function(){
					$('a[href^="#"], a[href*="#"]').live('click',(function(){
						$('.tip_detail').scrollTo( 'a[name="' + $(this).attr('href').replace('#', '').replace(document.URL, '') +'"]', 1500, { easing:'swing', queue:true, axis:'xy', margin:true, offset:-50 } );
						return true;
					}));
				}
			});

		}
		return false;
	});




	$(".askforstinger").click(function(){
		var url = "/ajax/askforstinger"
		$.nyroModalManual({
			url : url,
			closeButton : '',
			endFillContent : function(elts, settings){
				var form = elts.content.find('form');
				$(form).addClass('nyroModal');
			}
		});
		return false;
	});

	$("#interests").hide();

	$("#interests-link").click(function(){
		var content = $("#interests").html();
		$.nyroModalManual({
			height : 400,
			width: 400,
			content : content,
			endFillContent: function(elts, settings){
				$('#interests input:checked').each(function(i) {
					$('#nyroModalContent input[name='+this.name+']').attr('checked', true);
				});
			},
			beforeHideContent : function(elts, settings, callback){
				$('#interests input:checked').each(function(i) {
					$(this).attr('checked', false);
				});
				$("#nyroModalContent input:checked").each(function(i) {
					$('#interests input[name='+this.name+']').attr('checked', true);
				});
				callback();
			}
		});
		return false;
	});

	$("form#competition input[type = 'submit']").click(function(){
		var compId = $(this).parents('form').find('input[name="competition_id"]').val();
		if($(this).parents('form').find('div.competition-userdata-' + compId).css('display') == 'block'){
			return true;
		} else {
			$(this).parents('form').find('div.competition-userdata-' + compId).slideDown();
			$(this).unbind('click');
			return false;
		}
	});

    $('#login-password').focus(function() {
        $(this).value = '';
        $('#login-password').remove();
        $('#login-html').append('<input id="login-password-new" class="text required" type="password" name="password_plain" />');
        $('#login-password-new').focus();
    });


    $("#lang-switch").msDropDown();
   

});
function switchPage(value) {
    window.location.href = 'http://' + value;
}
function show_tab(e) {
    $('#tab_photo').removeClass();
    $('#tab_map').removeClass();
    $('#tab_drivein').removeClass();
    $(e).addClass("active");
    $('#layer_tab_photo').css('display','none');
    $('#layer_tab_map').css('display','none');
    $('#layer_tab_drivein').css('display','none');
    $('#layer_'+$(e).attr('id')).css('display','block');

}

function showFlyer(flashfile, flyerid, domain, site_access_name, site_access_type) {
	var content = '<div id="flashFlyer"></div>';
	var flashvars  = {};
	var params     = {};
	params.quality = "high";
	params.scale = "noScale";
	params.salign = "TL";
	params.wmode = "opaque";
	flashvars.domain = domain;
	flashvars.site_access_name = site_access_name;
	flashvars.site_access_type = site_access_type;
	flashvars.id = flyerid;
	var attributes = null;

	$.nyroModalManual({
		closeButton: '',
		content : content,
		height: 620,
		width: 880,
		css: {wrapper: { top: '50%', border: 'none'}, loading: { top: '50%'}}
    });
	swfobject.embedSWF(flashfile, "flashFlyer", "880", "580", "8", false, flashvars, params, attributes);
}

function close(){
	$.nyroModalRemove();
}

function printWindow(url, title){
    var PrintWindow = window.open(url, '_blank', "width=600,height=250,left=300,top=300");
    PrintWindow.focus();
	PrintWindow.setTimeout("print()", 2000);
}

