var blnIE6 = false;
var blnIE7 = false;
if ($.browser.msie && $.browser.version == "6.0") blnIE6 = true;
if ($.browser.msie && $.browser.version == "7.0") blnIE7 = true;
var htmlNoFlash = '<div class="warning"><div class="melding"><p>U beschikt niet over de laatste <span>Adobe Flash player</span> om de site goed te kunnen bekijken.</p><p class="small">Download de player <em>gratis</em> op de site van Adobe.</p><a href="http://get.adobe.com/flashplayer/" target="_blank" title="Adobe Flash Player"><img src="/lib/images/btn_get_flash.png" alt="Get Flashplayer" /></a></div></div>';
var pathExpressInstallFile = escape("/lib/flash/expressInstall.swf");

function initPopups() {
/*
    $.fn.nyroModal.settings.regexImg = '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$|image.aspx';
    $.fn.nyroModal.settings.minWidth = 0;
    $.fn.nyroModal.settings.minHeight = 0;
*/
}

function initContentFlash() {
    $('.contentflash').each(
        function() {
            var strId = $(this).attr('id');
            var strParams = $(this).find('a').attr('rel').split('|');

            $('#' + strId).flashembed(
            {
                src: strParams[0],
                version: [strParams[1]],
                width: strParams[2],
                height: strParams[3],
                expressInstall: pathExpressInstallFile,
                wmode: 'transparent',
                scale: 'noscale'
            })
        }
    );
}

function initMenu()
{

    if (blnIE6) $('#menu').css('height',274);
    $('#menu').flashembed(
    {
        src: '/lib/flash/StandaloneRibbonMenu.swf',
        version: [10,0],
       // expressInstall: pathExpressInstallFile,
        onFail: function(version){
            var a = $('#menu #noflash').html();
            $('#menu').html(a);
            $('#content').append('<div class="paragraph">' + htmlNoFlash + '</div>');
        },
        wmode: 'transparent',
        scale: 'noscale'
        
        
    },
    {
        audioUrl: escape('/lib/audio/Track27.mp3'),
        menuXmlPath: escape('/lib/xml/menu.ashx?taal=' + strTaal + '&sc=' + intSitecatId + '&id=' + intStructuurId+'&r='+Math.random())

       })

}

function initFlash() {

	var strJeTuin_nl = '/huis_tuin/8/producten/10/je_tuin.aspx';
	var strJeGazon_nl = '/huis_tuin/8/producten/11/je_gazon.aspx';
	var strJeHuis_nl = '/huis_tuin/8/producten/9/je_huis.aspx';
	var strProductenLandscaping_nl = '/landscaping/39/producten.aspx';
	var strProductenTuinbouw_nl = '/land_tuinbouw/31/producten.aspx';
	var strProductenSportgolf_nl = '/sport_golf/25/producten.aspx';
	var strCopyright_nl = '/over_pure/14/copyright.aspx';
	var strVoorwaarden_nl = '/over_pure/13/algemene_voorwaarden.aspx';
	var strContact_nl = '/over_pure/6/contact.aspx';
	var strZoek_nl = '/over_pure/15/zoek.aspx';

	var strJeTuin_en = '/house_garden/8/products/9/your_house.aspx';
	var strJeGazon_en = '/house_garden/8/products/11/your_lawn.aspx';
	var strJeHuis_en = '/house_garden/8/products/9/your_house.aspx';
	var strProductenLandscaping_en = '/landscaping/39/products.aspx';
	var strProductenTuinbouw_en = '/agri_horticulture/31/products.aspx';
	var strProductenSportgolf_en = '/sport_golf/25/products.aspx';
	var strCopyright_en = '/over_pure/14/copyright.aspx';
	var strVoorwaarden_en = '/about_pure/13/general terms.aspx';
	var strContact_en = '/about_pure/6/contact.aspx';
	var strZoek_en = '/about_pure/15/search.aspx';
	
    if (landingspage == '') landingspage = 'home';
    $('.homepage #flash').flashembed(
    {
        src: '/lib/flash/pure.swf',
        version: [10, 0],
        //expressInstall: pathExpressInstallFile,
        onFail: function(){
            $('body.homepage').css('background', 'url(/lib/images/bg_header.jpg) no-repeat center top');
            $('#paginacontainer').css('display','block');
        },
        wmode: 'window',
        scale: 'noscale'
    },
    {
        menuXml: escape('/lib/xml/menu.ashx'),  
        scOverpure: escape('1'),     
        scHuisTuin: escape('2'),
        scSportGolf: escape('3'),
        scLandTuinbouw: escape('4'),
        scLandscaping: escape('5'),
        nieuwsXml: escape('/lib/xml/nieuws.ashx'),
        audioUrl: escape('/lib/audio/Track27.mp3'),
        landingspage: landingspage,
        jetuin_nl: escape(strJeTuin_nl),
        jetuin_en: escape(strJeTuin_en),
        jegazon_nl: escape(strJeGazon_nl),
        jegazon_en: escape(strJeGazon_en),
        jehuis_nl: escape(strJeHuis_nl),
        jehuis_en: escape(strJeHuis_en),
        productenLandscaping_nl: escape(strProductenLandscaping_nl),
        productenLandscaping_en: escape(strProductenLandscaping_en),
        productenTuinbouw_nl: escape(strProductenTuinbouw_nl),
        productenTuinbouw_en: escape(strProductenTuinbouw_en),
        productenSportgolf_nl: escape(strProductenSportgolf_nl),
        productenSportgolf_en: escape(strProductenSportgolf_en),
        copyright_nl: escape(strCopyright_nl),
        copyright_en: escape(strCopyright_en),
        voorwaarden_nl: escape(strVoorwaarden_nl),
        voorwaarden_en: escape(strVoorwaarden_en),
        contact_nl: escape(strContact_nl),
        contact_en: escape(strContact_en),
        zoek_nl: escape(strZoek_nl),
        zoek_en: escape(strZoek_en),
        taal: strTaal
    })
}

function FlashSetHeightMenu(height)
{
    //alert(height);
    //if (height.indexOf('px')<0) height = height + 'px';
    //alert(height);
    if (blnIE6)
    {
        if ($('#productenmenu li.col2 a').css('position') == 'relative')
        {
            $('#productenmenu li.col2 a').css('position', 'static')
        }
        else
        {
            $('#productenmenu li.col2 a').css('position', 'relative')
        }
    }
    $('#menu').css('height',height);
}

$(document).ready(function() {

	//Initialiseer hier je scripts
	initContentFlash();
	initPopups();
	initForm();
	initFaq();
	initMenu();
	initFlash();
	fixPng();


	//$(".testproduct").nyroModalManual({ debug: true, handleError: function(elts, settings) { alert(settings.url); } });

	$('#producten li').hover(function() {
		$(this).addClass("hover")

	},
		function() {
			$(this).removeClass("hover")
		}
	);

	$('#producten li').css('cursor', 'pointer').click(function() {
		location.href = $(this).find('a').attr('href');
	});


	$('#menu li').hover(function() {
		$(this).addClass('sfHover');
	}, function() {
		$(this).removeClass('sfHover');
	});
});

function initForm()
{

    $('#chkHoogtehouden').click(function(){
        $('#txtVraag').removeClass('required');
    });
    
    /*
  	$('form.contact').validate({
  	    submitHandler: function(form) {
  	        $(form).nyroModalManual({
  	       
	            url: '/',
	           
	    
  	            endFillContent: function() {
  	            $('form.contact').resetForm();
  	             //   $('#nyroModalFull .paragraph').append('<p><a href="#" class="nyroModalClose" title="terug naar de site">&raquo; terug naar de site</a></p>')
  	            }
  	        });
  	    }
  	});
  	*/
  	$('form.contact').validate();
  	
    if (strTaal == 'nl')
    {
  	
	jQuery.extend(jQuery.validator.messages, {
        required: "verplicht",
        maxlength: jQuery.format("U kunt niet meer dan {0} karakters invoeren."),
        minlength: jQuery.format("U dient minimaal {0} karakters in te voeren."),
        rangelength: jQuery.format("U dient minimaal {0} en maximaal {1} karakters in te voeren."),
        email: "Een geldig emailadres is verplicht.",
        url: "Een geldig URL is verplicht.",
        date: "Een geldige datum is verplicht.",
        number: "Een geldig getal is verplicht.",
        digits: "Gebruik alleen cijfers.",
        equalTo: "Herhaal de invoer nogmaals.",
        range: jQuery.format("U dient een waarde tussen {0} en {1} in te voeren."),
        max: jQuery.format("U dient een waarde kleiner dan of gelijk aan {0} in te voeren."),
        min: jQuery.format("U dient een waarde groter dan of gelijk aan {0} in te voeren."),
        creditcard: "Een geldig creditcardnummer is verplicht."
	});
    }

    if (strTaal == 'en') {

        jQuery.extend(jQuery.validator.messages, {
            required: "required",
            maxlength: jQuery.format("U kunt niet meer dan {0} karakters invoeren."),
            minlength: jQuery.format("U dient minimaal {0} karakters in te voeren."),
            rangelength: jQuery.format("U dient minimaal {0} en maximaal {1} karakters in te voeren."),
            email: "A valid emailaddress is required.",
            url: "Een geldig URL is verplicht.",
            date: "Een geldige datum is verplicht.",
            number: "Een geldig getal is verplicht.",
            digits: "Gebruik alleen cijfers.",
            equalTo: "Herhaal de invoer nogmaals.",
            range: jQuery.format("U dient een waarde tussen {0} en {1} in te voeren."),
            max: jQuery.format("U dient een waarde kleiner dan of gelijk aan {0} in te voeren."),
            min: jQuery.format("U dient een waarde groter dan of gelijk aan {0} in te voeren."),
            creditcard: "Een geldig creditcardnummer is verplicht."
        });
    }

	//$('.contact .required').each(function(){ $(this).parent().append($(this).parent().find('noscript').text()); });
}

function initFaq()
{
	if (inBodyClass("faq"))
	{
		$('.faq h3').css('cursor','pointer').click(function(){
			$(this).parent().find(".questions").toggle();
			$(this).toggleClass("show");
			if (blnIE6 || blnIE7) $(this).parent().toggleClass('ie6bug');
			return false;
		});

		$('.faq .question').click(function(){ $(this).parent().find(".answer").toggle(); return false; });
		$('.faq .questions').hide().find(".answer").toggle();
		$('.faq h3').toggleClass("show");
		if (blnIE6|| blnIE7) $('.faq_thema').toggleClass('ie6bug');
		
		
	}

	$('.no_answer a').click(function() {
	    $.nyroModalManual({
	        url: $(this).attr('href') + '#nyro',
	        endShowContent: function() {

	            $('#faqvraagform').attr('action', '/mail.aspx');
	            $('#faqvraagform').validate({
	                submitHandler: function(form) {

	                    $(form).nyroModalManual({
	                        endFillContent: function() {

	                            //$('#nyroModalFull .paragraph').append('<p><a href="#" class="nyroModalClose" title="terug naar de site">&raquo; terug naar de site</a></p>');


	                        }
	                    });
	                }
	            });
	        }
	    });
	    return false;
	});

	$('.nieterbij a').click(function() {
	    $.nyroModalManual({
	        url: $(this).attr('href') + '#nyro',
	        endShowContent: function() {

	            $('#faqvraagform').attr('action', '/mail.aspx');
	            $('#faqvraagform').validate({
	                submitHandler: function(form) {

	                    $(form).nyroModalManual({
	                        endFillContent: function() {

	                            //$('#nyroModalFull .paragraph').append('<p><a href="#" class="nyroModalClose" title="terug naar de site">&raquo; terug naar de site</a></p>');


	                        }
	                    });
	                }
	            });
	        }
	    });
	    return false;
	});

}

function inBodyClass(x) { return $('body[class*=' + x + ']').length>0 }


function fixPng() {

    $('#producten img.product').pngfix({
        sizingMethod: "scale"
    });	
    $('#leftcol .packshot img').pngfix({
        sizingMethod: "scale"
    });
    $('.berichten img.afbeelding').pngfix({
   		sizingMethod: "scale"
	});			 
}


