$(document).ready(function()
{
	/*
    $("#shopMenu > li > a.hasSubmenu").click(function() {
        if($(this).hasClass("expanded")) {
            //$(this).parent().find('.test').slideUp("medium");
            $(this).parent().find('.test').css('display', 'none');
        } else {
            //$(this).parent().find('.test').slideToggle("medium");
            $(this).parent().find('.test').css('display', 'block');
        };
        $(this).toggleClass("expanded").toggleClass("collapsed");
        return false;
	});
    */
    
    $('#showEvents').click(function() {
        $('#Events').show();
        $(this).hide();
    });
    
    $("#workshop").click(function() {
        if($("#workshop").is(':checked') == true) {
            $('.workshop').show();
            $totaal = parseInt($('#totaal').html());
            $extra = parseInt($('#kostensworkshop').html());
            $totaal += $extra;
            $('#totaal').html($totaal);
        } else {
            $('.workshop').hide();
            $totaal = parseInt($('#totaal').html());
            $extra = parseInt($('#kostensworkshop').html());
            $totaal -= $extra;
            $('#totaal').html($totaal);
        }
    });
    
    $(".naalden").click(function() {
        if($(this).is(':checked') == true) {
            $totaal = parseFloat($('#totaal').html());
            $extra = parseFloat($(this).val());
            $totaal += $extra;
            $('#totaal').html($totaal);
        } else {
            $totaal = parseFloat($('#totaal').html());
            $extra = parseFloat($(this).val());
            $totaal -= $extra;
            $('#totaal').html($totaal);
        }
    });
    
    $("#kleuren").selectbox();

	$('#contentOverzicht').jScrollPane({wheelSpeed:50, scrollbarMargin:10});
            
	$("a[rel='lightbox']").colorbox();
    
    $('.externalLightbox').click(function(){
        $('a[rel=lightbox]:first').click();
        return false;
    });
    
    $('.externalLightboxWithId').click(function(){
        $('a[rel=lightbox]:visible').click();
        return false;
    });  
    
    $('.hasSubmenu').mouseenter(function()
    {
        $(this).children('ul#submenu').show();
    });
    
    $('.hasSubmenu').mouseleave(function()
    {
        $(this).children('ul#submenu').hide();
    });
    
    $(".tooltip").tooltip({ 
        bodyHandler: function() { 
            return $($(this).attr("href")).html(); 
        }, 
        showURL: false 
    });
    
    $(".shopTooltip").tooltip({ 
        bodyHandler: function() { 
            return $($(this).attr("href")).html(); 
        }, 
        showURL: false 
    });
    
    $(".omaTooltip").tooltip({ 
        bodyHandler: function() { 
            return $($(this).attr("href")).html(); 
        },
        extraClass: "oma", 
        showURL: false 
    });
    
    $('.kopieAdres').click(function()
    {
        $('#afleverStraat').val($('#straat').val());
        $('#afleverPostcode').val($('#postcode').val());
        $('#afleverPlaats').val($('#plaats').val());
        $('#afleverLand').val($('#land').val());
    });
        
     
    
    $('.job').click(function()
    {
        return false;
    });
    
    $('.job').mouseover(function()
    {
        $('.person').removeClass('active');
        $('.job').removeClass('active');
        $('.overlay').show();
        $('.' + this.id).hide();
        $('.person_' + this.id).addClass('active');
    });
    
    $('.job').mouseout(function()
    {
        $('.' + this.id).show();
        $('.person_' + this.id).removeClass('active');
    });
    
    $('.person').mouseover(function()
    {
        $('.person').removeClass('active');
        $('.job').removeClass('active');
        $('.overlay').show();
        $temp1 = $(this).attr('title');
        $jobs = $temp1.split(' ');
        for($i = 0; $i < $jobs.length; $i++)
        {
            $('#' + $jobs[$i]).addClass('active');
        }
        $('#overlay_' + this.id).hide();
    });
    
    $('.person').mouseout(function()
    {
        $temp1 = $(this).attr('title');
        $jobs = $temp1.split(' ');
        for($i = 0; $i < $jobs.length; $i++)
        {
            $('#' + $jobs[$i]).removeClass('active');
        }
        $('#overlay_' + this.id).show();
    });
    var $first = true;
    $('.image').mouseover(function()
    {
        if ($first)
        {
            $('.overlay').show();
        }
        $first = false;
    });
    
    $('.overlay').mouseover(function()
    {
        $('.person').removeClass('active');
        $('.job').removeClass('active');
        $('.overlay').show();
        $id = this.id;
        $temp = $id.split('_');
        $person = $temp[1];
        $('#' + $person).addClass('active');
        
        $temp1 = $(this).attr('title');
        $jobs = $temp1.split(' ');
        for($i = 0; $i < $jobs.length; $i++)
        {
            $('#' + $jobs[$i]).addClass('active');
        }
        $(this).hide();
    });
    $('.image').mouseout(function()
    {
        $id = $(this).next('.overlay').attr('id');
        $temp = $id.split('_');
        $person = $temp[1];
        $('#' + $person).removeClass('active');
        
        $temp1 = $(this).next('.overlay').attr('title');
        $jobs = $temp1.split(' ');
        for($i = 0; $i < $jobs.length; $i++)
        {
            $('#' + $jobs[$i]).removeClass('active');
        }
        
        $(this).next('.overlay').show();
    });
    
    
    $('.linkShop, #slider #imageOverlay, #closeShop, #slider #imageOverlayOma, #halfCirkelBrei img, #imageOverlayMade img').click(function()
    {
        $(".contentSlider").animate({width:'toggle'},2000);
        return false;
    });
    
    $('.styleswitch').click(function()
	{
		switchStylestyle(this.getAttribute("rel"));
        $(".styleswitch").removeClass('active');
        $(this).addClass('active');
        $src = $(this).children('img').attr('src');
        $src = $src.replace('_active', '');
        $src = $src.replace('.', '_active.');
        $src = $src.replace('_hover', '');
        $(this).children('img').attr('src', $src);
        $(this).children('img').unbind('mouseover');
        $(this).children('img').unbind('mouseout');
        $(".styleswitch").each(function()
        {
            if (!$(this).hasClass('active'))
            {
                $src = $(this).children('img').attr('src');
                $src = $src.replace('_active', '');
                $hoversrc = $src.replace('.', '_hover.');
                $(this).children('img').attr('src', $src);
                $(this).children('img').mouseover(function()
                {
                    $src = $(this).attr('src');
                    $src = $src.replace('_hover', '');
                    $src = $src.replace('_active', '');
                    $hoversrc = $src.replace('.', '_hover.');
                    $(this).attr('src', $hoversrc);
                });
                $(this).children('img').mouseout(function()
                {
                    $src = $(this).attr('src');
                    $src = $src.replace('_hover', '');
                    $src = $src.replace('_active', '');
                    $(this).attr('src', $src);
                });
            }
        });
        
		return false;
	});
    
    $(".styleswitch").each(function()
    {
        $(this).children('img').mouseover(function()
        {
            $src = $(this).attr('src');
            $src = $src.replace('_hover', '');
            $src = $src.replace('_active', '');
            $hoversrc = $src.replace('.', '_hover.');
            $(this).attr('src', $hoversrc);
        });
        $(this).children('img').mouseout(function()
        {
            $src = $(this).attr('src');
            $src = $src.replace('_hover', '');
            $src = $src.replace('_active', '');
            $(this).attr('src', $src);
        });
    });
    
    
    var c = readCookie('style');
    if (!c)
    {
        c = 'normal';
    }
	switchStylestyle(c);	
    
    $src = $('#' + c + 'Letters').children('img').attr('src');
    $src = $src.replace('.', '_active.');
    $src = $src.replace('_hover', '');
    $('#' + c + 'Letters').children('img').attr('src', $src);
    $('#' + c + 'Letters').addClass('active');
    $('#' + c + 'Letters').children('img').unbind('mouseover');
    $('#' + c + 'Letters').children('img').unbind('mouseout');	
    
    
});

function switchStylestyle(styleName)
{
  $('link[@rel*=style][title]').each(function(i)
  {
     this.disabled = true;
     if (this.getAttribute('title') == styleName) this.disabled = false;
  });
  createCookie('style', styleName, 365);
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}
