﻿var isNav4, isNav6, isIE4, isIE;
    var newHeight;
    var newWidth;
    var mainHeight = 550;
    var mainWith = 550;
    
/*
 * Browser version snooper; determines your browser
 * (Navigator 4, Navigator 6, or Internet Explorer 4/5)
 */
function setBrowser()
{
    if (navigator.appName.indexOf("Explorer") >= 0)
    {
        isIE = true;
    }
    
    if (navigator.appVersion.charAt(0) == "4")
    {
        if (navigator.appName.indexOf("Explorer") >= 0)
        {
            isIE4 = true;            
        }
        else
        {
            isNav4 = true;
        }
    }
    else if (navigator.appVersion.charAt(0) > "4")
    {
        isNav6 = true;
    }
}
setBrowser();

/*
 *
 * Move a given id.  If additive is true,
 * then move it by xValue dots horizontally and
 * yValue units vertically.  If additive is
 * false, then move it to (xValue, yValue)
 *
 * Note: do not precede the id with a # -- it will be
 * appended when searching the stylesheets
 *
 * Note also: length units are preserved in Navigator 6
 * and Internet Explorer. That is, if left is 2cm and
 * top is 3cm, and you move to (4, 5), the left will
 * become 4cm and the top 5cm.
 *
 */
function generic_move( id, xValue, yValue, additive )
{
    var left = getIdProperty(id, "left");
    var top = getIdProperty(id, "top");
    var leftMatch, topMatch;

    if (isNav4)
    {
        leftMatch = new Array( 0, left, "");
        topMatch = new Array( 0, top, "");
    }
    else if (isNav6 || isIE4 )
    {
        var splitexp = /([-0-9.]+)(\w+)/;
        leftMatch = splitexp.exec( left );
        topMatch = splitexp.exec( top );
        if (leftMatch == null || topMatch == null)
        {
            leftMatch = new Array(0, 0, "px");
            topMatch = new Array(0, 0, "px");
        }
    }
    left = ((additive) ? parseFloat( leftMatch[1] ) : 0) + xValue;
    top = ((additive) ? parseFloat( topMatch[1] ) : 0) + yValue;
    setIdProperty( id, "left", left + leftMatch[2] );
    setIdProperty( id, "top", top + topMatch[2] );
}

/*
 *
 * Move a given id to position (xValue, yValue)
 *
 */
function moveIdTo( id, x, y )
{
    generic_move( id, x, y, false );
}

/*
 *
 * Move a given id to (currentX + xValue, currentY + yValue)
 *
 */
function moveIdBy( id, x, y)
{
    generic_move( id, x, y, true );
}

function getStyleBySelector( selector )
{
   var sheetList = document.styleSheets;
   var ruleList;
   var i, j;

   /* look through stylesheets in reverse order that
      they appear in the document */
   for (i=sheetList.length-1; i >= 0; i--)
   {
       ruleList = sheetList[i].cssRules;
       for (j=0; j<ruleList.length; j++)
       {
           if (ruleList[j].type == CSSRule.STYLE_RULE && 
               ruleList[j].selectorText == selector)
           {
               return ruleList[j].style;
           }   
       }
   }
   return null;
}

/*
 *
 * Given an id and a property (as strings), return
 * the given property of that id.  Navigator 6 will
 * first look for the property in a tag; if not found,
 * it will look through the stylesheet.
 *
 * Note: do not precede the id with a # -- it will be
 * appended when searching the stylesheets
 *
 */
function getIdProperty( id, property )
{
    if (isNav6)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            if (styleObject[property])
            {
                return styleObject[ property ];
            }
        }
       
        styleObject = getStyleBySelector( "#" + id );
        return (styleObject != null) ?
            styleObject[property] :
            null;
    }
    else if (isNav4)
    {
        return document[id][property];
    }
    else
    {
        return document.all[id].style[property];
    }
}

/*
 *
 * Given an id and a property (as strings), set
 * the given property of that id to the value provided.
 *
 * The property is set directly on the tag, not in the
 * stylesheet.
 *
 */
function setIdProperty( id, property, value )
{
    if (isNav6)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            styleObject[ property ] = value;
        }
        
        /*
        styleObject = getStyleBySelector( "#" + id );
        if (styleObject != null)
        {
            styleObject[property] = value;
        }
        */
    }
    else if (isNav4)
    {
        document[id][property] = value;
    }
    else if (isIE4)
    {
         document.all[id].style[property] = value;
    }
}





function ToonMelding()
{
    jQuery('#melding').fadeIn().idle(2000).fadeOut('slow');
}

function VerbergMelding()
{   
    jQuery('#melding').fadeOut('slow');  
}

function SlideOutMelding(){
	winkelmandPos = $("#kolom #winkelmand h2").position();
	//$("#melding").css({'top':winkelmandPos.top});
	
	//jQuery('#melding').idle(1600).animate({top:winkelmandPos.top, left:"100%", opacity: 0}, {duration:2000, easing:'easeInExpo', queue:true});
	jQuery('#melding').idle(1600).animate({top:winkelmandPos.top, left:"100%", opacity: 0}, 2000, 'easeInExpo', function(){
		jQuery('#melding').css({display:'none'});
	});
	//.animate( { left: "-50%" }, { duration: 0, queue: true });	
}

function AddToCart2(productid)
{   
    try
    {
        var aantalElem = window.document.getElementById("aantal_" + productid);
        var aantal = aantalElem.value;
		
        if (isNaN(aantal))
            aantal = "1";
        
        addtocart = true;
        document.location.href = "/shop.aspx?addtocart=" + productid + "&quantity=" + aantal + "&ShowProdID=" + productid;
    }
    catch (e)
    {
        Alert(e.message);
    }
}  

function AddToCart(productid, path)
{   
    try
    {
    
    
        var aantalElem = window.document.getElementById("aantal_" + productid);
        var aantal = aantalElem.value;

        if (isNaN(aantal))
            aantal = "1";
            
        if (path.indexOf("melding=") > -1)
        {
            path = path.substring(0, path.indexOf("melding=") - 1);
        }     
        
        addtocart = true;
        
    
        if (path.indexOf("?") == -1)
        {            
            document.location.href = path + "?addtocart=" + productid + "&quantity=" + aantal; // /wijnoverzichten/default.aspx?addtocart=" + productid + "&quantity=" + aantal
        }
        else
        {            
            document.location.href = path + "&addtocart=" + productid + "&quantity=" + aantal; // /wijnoverzichten/default.aspx?addtocart=" + productid + "&quantity=" + aantal
        }
        
    }
    catch (e)
    {
        alert(e.message);
    }
}   
function AddToFav(productid, path)
{   
    try
    {           
        if (path.indexOf("melding=") > -1)
        {
            path = path.substring(0, path.indexOf("melding=") - 1);
        }     
            
        if (path.indexOf("?") == -1)
        {            
            document.location.href = path + "?addfav=" + productid;
        }
        else
        {
            document.location.href = path + "&addfav=" + productid; 
        }
    }
    catch (e)
    {
        alert(e.message);
    }
} 
function DelFav(productid, path)
{   
    try
    {           
        if (path.indexOf("melding=") > -1)
        {
            path = path.substring(0, path.indexOf("melding=") - 1);
        }     
            
        if (path.indexOf("?") == -1)
        {            
            document.location.href = path + "?delfav=" + productid;
        }
        else
        {
            document.location.href = path + "&delfav=" + productid; 
        }
    }
    catch (e)
    {
        alert(e.message);
    }
}  
function Zoek()
{
    try
    {
        var term = window.document.getElementById("zoekcriterium").value;
        
        if (term.length > 1)
        {
            term = term.replace("wijn", " ");
            term = term.replace("wijnen", " ");
        
 
            top.document.location.href = "/Zoeken/" + term;
        }
        else
        {
            window.status = "geen zoek term opgegeven";
        }          
    }
    catch (e)
    {
        alert(e.message);
    }
}

function mod(div,base) 
{
    try
    {    
        return Math.round(div - (Math.floor(div/base)*base));
    }
    catch (e)
    {
        alert(e.message);
    }
}

function IsGeldigRekNo(rekno)
{    
    var nummer
    var i;
    var y;
    var n;
    var sum = 0;
    
    try
    {
        rekno = jQuery.trim(rekno);
        rekno = rekno.replace(".", "");

        if (rekno.length == 0) return false;
        if (rekno.length < 6) return false;
        if (rekno.length == 6 || rekno.length == 7) return true; // postbank giro nummer
        
        if (rekno.length == 9)
            rekno = "0" + rekno;
            
        if (rekno.length == 10)
		{		
			nummer = parseInt(rekno);
			
			y = rekno.length;

			for (i = 0; i < rekno.length; i++)
			{
				n = parseInt(rekno.charAt(i))
				sum += n * y;
				y--;
			}

			if (mod(sum, 11) == 0)
			{
				return true;
			}
			else
			{         
				return false;
			}
		}

		return false;
		//if (nummer < 100000000) return true; // waarschijnlijk postgirobankno
    }
    catch (e)
    {
        alert(e.message);
        return false;
    }
}

var placeholder = "ctl00_cph_content_";
function controleerRekNo()
{
    var oke = true;
    var rekno = "";
    
    try
    {
   //alert($('input[type=radio][name=ctl00$cph_content$rblBetaalOptie]:checked').val());

        
        if ($('input[type=radio][name=ctl00$cph_content$rblBetaalOptie]:checked').val() == 'eenmalige incasso')
        {
            rekno = jQuery('#' + placeholder + 'tb_rekeningnummer').val();
            
            if (rekno.length == 0)
            {
                jQuery("#reknomelding").html("Voer je (giro)bankrekeningnummer in.");
                jQuery("#reknomelding").show();
                
                return false;
            }
            
            oke = IsGeldigRekNo(rekno);
           
            if (!oke)
            {
                jQuery("#reknomelding").html("Bankrekeningnummer is incorrect, controleer je bankrekeningnummer.");
                jQuery("#reknomelding").show();            
            }
            else
                jQuery("#reknomelding").hide();
                        
        }
        else
            jQuery("#reknomelding").hide();
                    

        
        return oke;
    }
    catch (e)
    {
        return false;
    }
}
function ValidateBestelForm()
{
    var result = true;
    
    if (jQuery('#' + placeholder + 'GeboortedatumTextBox').val().length == 0)
    {
        result = false;
        jQuery('#spanGeboortedatum').show();
    }
    else
        jQuery('#spanGeboortedatum').hide();
    
    return result;
}
function ValidateRegistratieForm()
{
    var result = true;
    
    if (jQuery('#' + placeholder + 'tbGebDat').val().length == 0)
    {
        result = false;
        jQuery('#spanGeboortedatum').show();
    }
    else
    {
        jQuery('#spanGeboortedatum').hide();
    }
    
    return result;
}

function ValidateNAWMijnGrape()
{
    var result = true;
    
    if (jQuery('#' + placeholder + 'tbGebDate').val().length == 0)
    {
        result = false;
        jQuery('#spanGeboortedatum').show();
    }
    else
    {
        jQuery('#spanGeboortedatum').hide();
    }
    if (jQuery('#' + placeholder + 'tbPostcodeCijfers').val().length == 0)
    {
        result = false;
        jQuery('#divErrorPostcode').show();
    }
    else if (jQuery('#' + placeholder + 'tbPostcodeLetters').val().length == 0)
    {
        result = false;
        jQuery('#divErrorPostcode').show();
    }
    else
    {
        jQuery('#divErrorPostcode').hide();
    }
    
    return result;
}

function GetDate(datetext)
{
    var d = new Date();
    var arr;
    var dag, maand, jaar;
    
    try
    {
        if (datetext.length == 0) return d;
        
        arr = datetext.split("-");
        dag = parseInt(arr[0]);
        maand = parseInt(arr[1]) - 1;
        jaar = parseInt(arr[2]);
        
        d.setFullYear(jaar, maand, dag);
        
        return d;                
    }
    catch (e)
    {
        return d;
    }
}

/* FP winnaar banner START*/
function initRandomMovement(img, x, y, dir){
  var rm_img = new Image();
  rm_img.src = img;
  
  var imgh = 20;
  var imgw = 20;
  var timer = 40; //setTimeout speed.
  var min = 1;    //slowest speed.
  var max = 2;    //fastest speed.
  
  var idx = 1;
  idx = parseInt(document.images.length);
  if (document.getElementById("pic"+idx)) idx++;
  var stuff = "<div id='pic"+idx+"' style='position:absolute;z-index:10;"
  +"top:2px;left:2px;height:"+imgh+"px;width:"+imgw+"px;"
  +"overflow:hidden'><img src='"+rm_img.src+"' alt=''/><\/div>";
  //document.write(stuff);
  $("div#winnaar-img").append(stuff);

  var h,w,r,temp;
  var d = document;
  //var y = 1;
  //var x = 1;
  //var dir = 45;   //direction.
  var acc = 1;    //acceleration.
  var newacc = new Array(1,0,1);
  var vel = 1;    //initial speed.
  var sev = 0;
  var newsev = new Array(1,-1,2,-2,0,0,1,-1,2,-2);
  
  //counters.
  var c1 = 0;    //time between changes.
  var c2 = 0;    //new time between changes.

  var pix = "px";
  var domWw = (typeof window.innerWidth == "number");
  var domSy = (typeof window.pageYOffset == "number");
  
  if (domWw)
     r = window;
  else{ 
    if (d.documentElement && typeof d.documentElement.clientWidth == "number" && d.documentElement.clientWidth != 0)
      r = d.documentElement;
    else{
      if (d.body && typeof d.body.clientWidth == "number")
         r = d.body;
    }
  }

  function scrl(yx){
    var y,x;
    if (domSy){
      y = r.pageYOffset;
      x = r.pageXOffset;
    }
    else{
      y = r.scrollTop;
      x = r.scrollLeft;
    }
    //x = $("div#winnaar-img").width();
    //y = $("div#winnaar-img").height();
    return (yx == 0)?y:x;
  }
  

  function newpath(){
    sev = newsev[Math.floor(Math.random()*newsev.length)];
    acc = newacc[Math.floor(Math.random()*newacc.length)];
    c2 = Math.floor(20+Math.random()*50);
  }
  

  function moveit(){
    var vb,hb,dy,dx,curr;
    if (acc == 1) vel +=0.05;
    if (acc == 0) vel -=0.05;
    if (vel >= max) vel = max;
    if (vel <= min) vel = min;
    c1++;
    if (c1 >= c2){
      newpath();
      c1=0;
    }
    curr = dir+=sev;
    dy = vel * Math.sin(curr*Math.PI/180);
    dx = vel * Math.cos(curr*Math.PI/180);
    y+=dy;
    x+=dx;
    //horizontal-vertical bounce.
    vb = 180-dir;
    hb = 0-dir;
    //Corner rebounds?
    if ((y < 1) && (x < 1)){y = 1; x = 1; dir = 45;}
    if ((y < 1) && (x > w)){y = 1; x = w; dir = 135;}
    if ((y > h) && (x < 1)){y = h; x = 1; dir = 315;}
    if ((y > h) && (x > w)){y = h; x = w; dir = 225;}
    //edge rebounds.
    if (y < 1) {y = 1; dir = hb;}
    if (y > h) {y = h; dir = hb;}
    if (x < 1) {x = 1; dir = vb;}
    if (x > w) {x = w; dir = vb;}

    //Assign it all to image.
    $("#pic"+idx).css({top  : y + scrl(0) + pix});
    $("#pic"+idx).css({left : x + scrl(1) + pix});
    setTimeout(moveit,timer);
    }

    function init(){
      //temp = document.getElementByID("pic"+idx);
      //winsize();
      moveit();
    }
  
    if (window.addEventListener){
     //window.addEventListener("resize",winsize,false);
     window.addEventListener("load",init,false);
    }
    else if (window.attachEvent){
     //window.attachEvent("onresize",winsize);
     window.attachEvent("onload",init);
    }
};


/* FP winnaar banner START */
this.fadeWinnaar = function(){
  $("#winnaar-img img").fadeTo(1500,0, function(){
    $("#winnaar-img img").remove();
  });
}
/* FP winnaar banner END */


/* FP banner START */
this.fadeFPBanner = function(newActive){
  switch(newActive) {
  case "1a":
    $("div.decemberactie-img-3").fadeTo(3000,0, function(){
      setTimeout("fadeWinnaar2('2')",3000);
    });
    break;
  case "1b":
    $("div.decemberactie-img-2").fadeTo(3000,0, function(){
      setTimeout("fadeWinnaar2('3')",3000);
    });
    break;
  case "2":
    $("div.decemberactie-img-2").css({opacity:0,visibility:'visible'}).fadeTo(3000,1, function(){
      setTimeout("fadeWinnaar2('1b')",3000);
    });    
    break;
  case "3":
    $("div.decemberactie-img-3").css({opacity:0,visibility:'visible'}).fadeTo(3000,1, function(){
      setTimeout("fadeWinnaar2('1a')",3000);
    });
    break;
  }
}
/* FP banner END*/

/*relatie geschenk START*/
function checkEmail(id){
	email = $("#"+id).val();
	var ck_email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (!ck_email.test(email)) {
		$("#"+id).next().show("fast");
		return false;
	} else {
		$("#"+id).next().hide("fast");
		return true;
	}
}

function showGiftFolder(){
	target = $("#gifts-content-wrap .iframe-target").text();
	$("#gifts-folder-box").fadeOut();
	$("#gifts-content-wrap").animate({paddingBottom:"100px"});
	$("#gifts-offerte-aanvraag").animate({top:'613px',left:'376px'}, function(){
		$("#gifts-content-wrap .gifts-bg").css({background:"none"});
		$("#gifts-content-wrap .gifts-content").append('<iframe src="'+target+'" frameborder="0" width="948" height="586" allowtransparency="true"></iframe>');
	});
}
/*relatie geschenk END */

function initTooltips(){
	/* keurmerk icon tooltip */
	var keurmerkClasses = ["favoriet","bio","pers","weetje","winnaar"];
	for (var i in keurmerkClasses) {
		$(".keurmerktooltip."+keurmerkClasses[i]).qtip({
			content: "<img src='/images/keurmerk/header/"+keurmerkClasses[i]+"-tooltip.png' alt='tooltip' />",
			show: { when:{event:'mouseover'}, effect:{type:'slide'} },
			hide: { when:{event:'mouseout'}, effect:{type:'slide'} },
			position: {
				corner: {target: 'topRight', tooltip: 'bottomLeft'},
				adjust: {x: -35, y: 5, mouse: false}
			},
			style: {
				border: {width:	0},
				background: 'transparent'
			},
			show: { effect: { type: 'slide' } },
			hide: { effect: { type: 'slide' } }
		})
	};	
	
	/* category tooltips // colorized (looped for all classes) */
	var categorieClasses = [ ["bubbly","#9dced5"],["easy","#bdc91f"],["mellow","#eed912"],["rich","#d7a81a"],["rosy","#debdcc"],["blush","#d9361b"],["smooth","#a9100e"],["deep","#631872"],["honey","#d56e0f"] ];
	var oldSearchBoxColor = $("#menuzij #zoek label h2").css("color");
	
	for (var i in categorieClasses) {
		$("ul li.cat_tooltip."+categorieClasses[i][0]).qtip({
			show: 'mouseover',
			hide: 'mouseout',
			style: {
				width: 'auto', padding: 5, fontSize: '1.2em',
				border: { width: 3, radius: 3, color: categorieClasses[i][1] }
			},
			position: {
				corner: {target: 'topRight', tooltip: 'topLeft'},
				adjust: {x: -20, y: 5}
			}/*,
			api: {
				onShow: searchBoxColorize(categorieClasses[i][1]),
				beforeShow
				onHide: searchBoxDeColorize(oldSearchBoxColor)
				beforeHide
			}*/
		});
	};
		//ipad and iphone fix
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
    $("ul li.cat_tooltip."+categorieClasses[i][0]).qtip({
			show: 'click',
			hide: 'click',
			style: {
				width: 'auto', padding: 5, fontSize: '1.2em',
				border: { width: 3, radius: 3, color: categorieClasses[i][1] }
			},
			position: {
				corner: {target: 'topRight', tooltip: 'topLeft'},
				adjust: {x: -20, y: 5}
			}
    }).live('touchend', function() {
    var el = $(this);
    var link = el.attr('href');
    window.location = link;
});
};
	
	/* infotips */
	$("a.infotip, img.infotip").qtip({
		position: {
			type: 'absolute',
			corner: {target: 'bottomLeft', tooltip: 'topLeft'},
			adjust: {x: -10, y: 3, mouse: false}
		}
	});
	
	/* infotips */
	$("span.infotip").qtip({
		position: {
			type: 'absolute',
			corner: {target: 'bottomLeft', tooltip: 'topLeft'},
			adjust: {x: -10, y: 3, mouse: false}
		}
	});
	//$("div.fav_del a.fav").css({opacity:0.90});
}

/* new customer // help overlay */
var currentHelpTabPage = 0;
var totalHelpPages = 0;
var helpTabDelay = 5000;
var switchHelpPageHook;

function searchBoxColorize(color){
	alert(color);
}

function searchBoxDeColorize(color){
	alert(color);
}


function initHelpTab(){
	docHeight = $(document).height();
	$("#welcomePopup").css({height:docHeight, opacity:0.6}).bind('click', closeHelpClick);
	$("#welcomePopup-inner .open").bind('click', openHelpClick);
	$("#welcomePopup-inner .welcomePopup-paging .paging").children().bind('click', function(e){
		if (!$("#welcomePopup-inner .welcomePopup-page").is(':animated'))
			manualSwitchHelpTabPage( $(this).text() );
	});
	$("#welcomePopup-inner .next").bind('click', function(e){
		if (!$("#welcomePopup-inner .welcomePopup-page").is(':animated'))
			manualSwitchHelpTabPage( currentHelpTabPage+1 );
	});
}

function manualSwitchHelpTabPage(page){
	clearTimeout(switchHelpPageHook);
	currentHelpTabPage = page - 1;
	switchHelpTabPage();
}

function switchHelpTabPage(){
	if (currentHelpTabPage < totalHelpPages) {
		var previousPage = currentHelpTabPage;
		currentHelpTabPage = currentHelpTabPage + 1;
	} else {
		var previousPage = totalHelpPages;
		currentHelpTabPage = 1;
	}
	
	$("#welcomePopup-inner .welcomePopup-paging .paging").idle(250).children().css({opacity:0.5});
	$("#welcomePopup-inner .welcomePopup-paging .paging").idle(250).children(":eq("+(currentHelpTabPage-1)+")").css({opacity:1});
		
	$("#welcomePopup-inner .welcomePopup-page:visible").animate({opacity:0});
	$("#welcomePopup-inner .welcomePopup-page.page"+currentHelpTabPage).css({opacity:0,display:'block'}).animate({opacity:1}, 1000, function(){
		$("#welcomePopup-inner .welcomePopup-page.page"+previousPage).css({opacity:0,display:'none'});	
		//auto switch to next tab
		//switchHelpPageHook = setTimeout("switchHelpTabPage()",helpTabDelay);
	});
}

/* new customer STATIC(!!) START */
var currentHelpTabPageStatic = 0;
var totalHelpPagesStatic = 0;
var helpTabDelayStatic = 5000;
var switchHelpPageHookStatic;

function manualSwitchHelpTabPageStatic(page){
	clearTimeout(switchHelpPageHookStatic);
	currentHelpTabPageStatic = page - 1;
	switchHelpTabPageStatic();
}

function switchHelpTabPageStatic(){
	if (currentHelpTabPageStatic < totalHelpPagesStatic) {
		var previousPageStatic = currentHelpTabPageStatic;
		currentHelpTabPageStatic = currentHelpTabPageStatic + 1;
		
		$("#welcomeBox .welcomeBox-paging .paging").idle(250).children().css({opacity:0.5});
		$("#welcomeBox .welcomeBox-paging .paging").idle(250).children(":eq("+(currentHelpTabPageStatic-1)+")").css({opacity:1});
			
		$("#welcomeBox .welcomeBox-page:visible").animate({opacity:0});
		$("#welcomeBox .welcomeBox-page.page"+currentHelpTabPageStatic).css({opacity:0,display:'block'}).animate({opacity:1}, 1000, function(){
			$("#welcomeBox .welcomeBox-page.page"+previousPageStatic).css({opacity:0,display:'none'});	
			//auto switch to next tab
			//switchHelpPageHook = setTimeout("switchHelpTabPageStatic()",helpTabDelayStatic);
		});
	} else {
		$("#welcomeBox").animate({opacity:0}, function(){
			$(this).css({display:'none'});
			$("#defaultFPBox").css({opacity:0,display:'block'}).animate({opacity:1});
			window.location.replace("/");
		});
	}
}
function newClientStatic() {
	if($("#welcomeBox").length > 0) {
		$("#defaultFPBox").css({display:'none'});
		$("#welcomeBox").css({display:'block'});
		
		currentHelpTabPageStatic = 1;
		totalHelpPagesStatic = $("#welcomeBox .welcomeBox-page").length;
		
		$("#welcomeBox .welcomeBox-paging .paging div:not(:first)").css({opacity:0.5});
		$("#welcomeBox .welcomeBox-paging .paging").children().bind('click', function(e){
			if (!$("#welcomeBox .welcomeBox-page").is(':animated'))
				manualSwitchHelpTabPageStatic( $(this).text() );
		});
		$("#welcomeBox .next").bind('click', function(e){
			if (!$("#welcomeBox .welcomeBox-page").is(':animated'))
				manualSwitchHelpTabPageStatic( currentHelpTabPageStatic+1 );
		});
	}
}
/* new customer STATIC(!!) END */

function openHelpClick() {
	if (!$("#welcomePopup-inner").is(':animated')) {

		currentHelpTabPage = 0;
		totalHelpPages = 0;
		$("#welcomePopup-inner .welcomePopup-paging").css({opacity:0});
		$("#welcomePopup-inner .welcomePopup-paging .paging div").css({opacity:0.5});
		$("#welcomePopup-inner .welcomePopup-paging .paging").children(":eq(0)").css({opacity:1});
		$("#welcomePopup-inner .welcomePopup-page.page").css({opacity:0,display:'none'});

		$("#welcomePopup-inner .sluiten").css({cursor:'pointer'});
		$("#welcomePopup").fadeIn(300, function(){
			$("#welcomePopup-inner .open img").animate({width:0,height:332}, 1000);
			$("#welcomePopup-inner .open").animate({width:0}, 1000, function(){$(this).hide()});
			$("#welcomePopup-inner").animate({left:'50%'},1000, function(){
				$("#welcomePopup-inner .open").unbind('click', openHelpClick);
				$("#welcomePopup-inner .open").css({cursor:'default'});
				$("#welcomePopup-inner .sluiten").bind('click', closeHelpClick);
				
				totalHelpPages = $("#welcomePopup-inner .welcomePopup-page").length;	
				$("#welcomePopup-inner .next").css({opacity:0,display:'block'}).idle(1000).animate({opacity:0.8});
				$("#welcomePopup-inner .welcomePopup-paging").idle(1000).animate({opacity:1});
				switchHelpPageHook = setTimeout("switchHelpTabPage()",500);
			});												
		});

	}
}
function closeHelpClick() {
	clearTimeout(switchHelpPageHook);
	if (!$("#welcomePopup-inner").is(':animated')) {		
		$("#welcomePopup-inner .open img").animate({width:92,height:332}, 1000);
		$("#welcomePopup-inner .open").css({cursor:'pointer'}).animate({width:117}, 1000);
		$("#welcomePopup-inner").animate({left:-290},1000, function(){
			$("#welcomePopup-inner .sluiten").unbind('click', closeHelpClick);
			$("#welcomePopup-inner .sluiten").css({cursor:'default'});
			$("#welcomePopup-inner .open").bind('click', openHelpClick);
			
			$("#welcomePopup-inner .welcomePopup-paging").css({opacity:0});
			$("#welcomePopup-inner .welcomePopup-page").css({opacity:0,display:'none'});
		});
		$("#welcomePopup").idle(1000).fadeOut(300);
	}
}

function initNewCustomer(){
	setTimeout("openHelpClick()",1000);
}

/* mijn grapedistrict menu check (set active tab) */
function setMijnGrapeMenu(){
	var $_GET = getQueryParams(document.location.search);
	if($_GET["page"]){
		switch($_GET["page"]){
			case "p":
			  $('ul.submenu li').removeClass('active');
			  $('li#libestellingen').addClass('active');
			  break;
			case "naw":
			  $('ul.submenu li').removeClass('active');
			  $('li#linaw').addClass('active');
			  break;
			case "ww":
			  $('ul.submenu li').removeClass('active');
			  $('li#liww').addClass('active');
			  break;
		}
	}
}
/*function getQueryParams(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}*/

function getQueryParams(qs) {
    qs = qs.split("+").join(" ");
	var count = 0;
    var params = {};
    var tokens;

    while ( (tokens = /[?&]?([^=]+)=([^&]*)/g.exec(qs)) && (count < 10) ) {
        params[decodeURIComponent(tokens[1])]
            = decodeURIComponent(tokens[2]);
		count += 1;
    }

    return params;
}

function startCamFeed(){
	$(".wijnadvies-video a.media").media({ 
		width:     334, 
		height:    232, 
		autoplay:  true,
		loop:      true,
		//src:       'http://stream.mediaweb.nl/grapedistrict', 
		src:       '/wijnadvies.asx',
		//src:	   'http://www.ccs-conference.eu/climate-neutral/090630UK.wmv',
		//attrs:     { attr1:  'attrValue1',  attr2:  'attrValue2' },  // object/embed attrs 
		params:    { uiMode:'none', loop:true, ShowControls:false, ShowStatusBar:false, ShowDisplay:false }, // object params/embed attrs 
		caption:   false // supress caption text 
	});
	if(!$.browser.msie){
		//$('.wijnadvies-video .media embed').attr("id", 'livefeed');
		$('.wijnadvies-video .media embed').attr("uiMode", 'none');
		//document.getElementById('player').uiMode = 'none'
	}
}



$(document).ready(function(){						  
	// wijndetails tab code
	$(".wijn-details .tabs-wrap .tab").click(function(){
		$(".wijn-details .tabs-wrap .tab").removeClass("active");
		$(this).addClass("active");
		$(".wijn-details .content-wrap div").removeClass("active");
		newActive = $(this).children("div").attr('className');
		$(".wijn-details .content-wrap div."+newActive+"-wrap").addClass("active");
		
		extraInfoTXT = $(".wijninfo_overig table td.tdmid2").html();
		if( ((extraInfoTXT.indexOf('H3') != -1) || (extraInfoTXT.indexOf('h3') != -1)) && (newActive == "extra-info") ){
			$(".wijninfo_notes").css({display:'none'});
			$(".wijninfo_comment").css({display:'none'});
			$(".wijninfo_overig").css({display:'block'});
		} else {
			$(".wijninfo_overig").css({display:'none'});
			$(".wijninfo_notes").css({display:'block'});
			$(".wijninfo_comment").css({display:'block'});
		}
	});
	if($(".wijn-details .tabs-wrap .tab").length > 0){
		var wijnUrl = $(document).url();
		if(wijnUrl.hashSegment(0) == "recept" || wijnUrl.segment(0) == "recept"){
			$(".wijn-details .tabs-wrap .tab").removeClass("active");
			$(".wijn-details .tabs-wrap .tab .recept").parent().addClass("active");
			$(".wijn-details .content-wrap div").removeClass("active");
			$(".wijn-details .content-wrap div.recept-wrap").addClass("active");
		}
	}

	//bestelling rightnav anders vanaf stap2
	if($(".navright_choice.groep2 img").length > 0){
		$(".navright_choice.groep1").css({display:'none'});
		$(".navright_choice.groep2").css({display:'block'});
		var currentStap = $("ol#stappen li.current span").html();
		switch(true){
			case currentStap.indexOf("Stap 2") > -1:
				$(".navright_choice.groep2 .blijheidsgarantie")		.css({display:'block'});
				$(".navright_choice.groep2 .gegevensbescherming")	.css({display:'block'});
				$(".navright_choice.groep2 .bezorgen")				.css({display:'none'});
				$(".navright_choice.groep2 .betalen")				.css({display:'none'});
				// altijd aan: $(".navright_choice.groep2 .contact")				.css({display:'none'});
				break;
			case currentStap.indexOf("Stap 3") > -1:
				$(".navright_choice.groep2 .blijheidsgarantie")		.css({display:'block'});
				$(".navright_choice.groep2 .gegevensbescherming")	.css({display:'none'});
				$(".navright_choice.groep2 .bezorgen")				.css({display:'none'});
				$(".navright_choice.groep2 .betalen")				.css({display:'block'});
				// altijd aan: $(".navright_choice.groep2 .contact")				.css({display:'none'});
				break;
			case currentStap.indexOf("Stap 4") > -1:
				$(".navright_choice.groep2 .blijheidsgarantie")		.css({display:'block'});
				$(".navright_choice.groep2 .gegevensbescherming")	.css({display:'none'});
				$(".navright_choice.groep2 .bezorgen")				.css({display:'block'});
				$(".navright_choice.groep2 .betalen")				.css({display:'none'});
				// altijd aan: $(".navright_choice.groep2 .contact")				.css({display:'none'});
				break;
		}
		if( $("ol#stappen li.current span").html() == "" ){
			
		}
	}
	
	// gifts pagina JS code
	$("#gifts-folder-box").click(function(){
		showGiftFolder();
	});
	$("#gifts-offerte-aanvraag").click(function(){
		window.location="/gifts/offerteaanvraag.aspx";
	});
	$("#gifts-offerte-aanvraag.aanvraag2010").click(function(){
		window.location="/gifts/offerteaanvraag-2010.aspx";
	});
	
	// melding pop-up alignment
	/*if($("#kolom #winkelmand").length > 0){
		winkelmandPos = $("#kolom #winkelmand h2").position();
		$("#melding").css({'top':winkelmandPos.top});
	}*/
	
	initTooltips();
	 
	//init helptab
	initHelpTab();
	
	//mijn grape menu controls
	if($("ul.submenuMijngrape").length > 0) {
		setMijnGrapeMenu();
	}
	
	// Wijnadvies video init; starten NA volledig inladen coBrowser JS, ander wordt het in IE niet goed geladen!	
	window.cbReady = function(){
		setTimeout('startCamFeed();',500);
	}
	//setTimeout('startCamFeed();',5000);
	
	// parental visual
	if($(".parental-visual").length > 0){
		setTimeout('$(".parental-visual img:eq(0)").fadeOut(2000);$(".parental-visual img:eq(1)").fadeIn(2000);',3000);		
	}
	
	
	if($(".actie-2011-02-visual").length > 0){
		$(".actie-2011-02-visual.clickable").css({cursor:"pointer"}).click(function(){
			visualFaderClick();
		});
		visualFaderItems = $(".actie-2011-02-visual").length;
		visualFader();
	}
	

	/*
	if($("#winkelmand-voordeelblok-switch").length > 0){
		alert('test');
		$("#winkelmand, #winkelmand-voordeelblok-switch").remove();
		$('#top5').before($("#voordelenblok-retailside"));
	}
	*/
});

 
var visualFaderActive = 0;
var visualFaderItems = 0;
var visualFaderTimer;

function visualFader(){
	visualFaderActive = visualFaderActive+1;
	if(visualFaderActive == visualFaderItems) visualFaderActive = 0;
	visualFaderTimer = setTimeout('$(".actie-2011-02-visual:visible").fadeOut(2000);$(".actie-2011-02-visual:eq('+visualFaderActive+')").fadeIn(2000);visualFader()',7000);
}

function visualFaderClick(){
	clearTimeout(visualFaderTimer);
	
	$(".actie-2011-02-visual:visible").fadeOut(2000);
	$(".actie-2011-02-visual:eq("+visualFaderActive+")").fadeIn(2000, function(){
		visualFader();
	});
}




function ByElement_btnIncassoPlaatsBestelling(delay)
{
    jQuery('#ctl00_cph_content_Img3').attr('src', '../images/spinner.gif')
    
    if (typeof (ByElement) == "function") {
        ByElement();
    }
    setTimeout("__doPostBack('ctl00$cph_content$btnIncassoPlaatsBestelling','');", delay);
}

function ByElement_bBevestigBest(delay) 
{
    jQuery('#ctl00_cph_content_Img2').attr('src', '../images/spinner.gif')

    if (typeof (ByElement) == "function") {
        ByElement();
    }
    setTimeout("javascript:__doPostBack('ctl00$cph_content$bBevestigBest','');", delay);
}
