﻿var popupIsShown = false;

$(document).ready(function()
{
    $(".navigationbalk").clone().insertAfter(".navigationbalk").removeClass("hoofdbalk").attr("id", "mainnav2").wrap("<div id='diap' class='diap'></div>");
    $(".col:first").addClass("firstcol");
    $("ul").not(".all_genres ul, .all_locatie ul").each(function()
    {
        $(this).find("li:first").addClass("first");
    });
	$("td.genrecol li").each(function(){
		if (($(this).attr("style") == "background-color: rgb(255, 255, 0);")	|| ($(this).attr("style") == "background-color: rgb(255, 215, 0);")){
			$(this).css("color","#999");
		}						  
	})
	//if ($(".overviewlist tr td.genrecol ul li").attr("style") == "background-color: #FFFF00;"){
		//alert($("td.genrecol li").attr("style"))
	//}
    setInterval("slideSwitch()", 5000);
	setInterval("slideBookmarks()", 5000);

    $(".pagination a").each(function()
    {
        if ($(this).attr("disabled") == "disabled")
        {
            $(this).css("display", "none");
        }
    })

    greyout = document.createElement("div");
    $(greyout).addClass("greyout").attr("id", "greyout").css("height", $(document).height() + "px");

    $("body").append(greyout);

    $("#greyout").bind("click", function(e)
    {
        hideGreyout();
		$("#aankondiging").hide();
    });
    $('.greyout').bgiframe();

    $(".vak_header a.resize").click(function()
    {
        parentVak = $(this).parents(".vak");
        if (parentVak.hasClass("v_maximized"))
        {
            parentVak.removeClass("v_maximized").addClass("v_minimized");
            // if ((parentVak.parent().attr("id") == "catchminimized") && (parentVak.hasClass("vakW1"))) {
            //                //alert("al in minimized en w = 1")
            //            } else {
            //                parentVak.appendTo("#catchminimized");
            //            }
        } else
        {
            parentVak.removeClass("v_minimized").addClass("v_maximized");
            // if (!parentVak.hasClass("vakW1")) {
            //                parentVak.prependTo("#catchmaximized");
            //            }
        };
        return false;
    });
	$("#aankondiging a.close").click(function(){
		$("#aankondiging").hide();											  
		hideGreyout();
		return false;
	});
    $("#mijnHFcontainer .togglesize").click(function()
    {
        if ($(this).parent().parent().hasClass("mhf_maximized"))
        {
            $(this).parent().parent().removeClass("mhf_maximized").addClass("mhf_minimized");
        } else
        {
            $(this).parent().parent().removeClass("mhf_minimized").addClass("mhf_maximized");

        }
        return false;
    });
	
	

   // $(".mhf_minimized").click(function()
//    {
//
//        $(this).removeClass("mhf_minimized").addClass("mhf_maximized");
//
//
//    });

    winWidth = $(window).width();
    $("#diap #mainnav2").css("width", winWidth);
    if ($.browser.msie)
    {
        winHeight = $(window).height();
        $("#diap").css("height", winHeight);
    }

    $(".nav, #mainnav li").hover(
        function()
        {
            //$("#diap").show();
			$("#diap").css("display","block");
            $('embed').css('visibility', 'hidden');
        },
        function()
        {
            //$("#diap").hide();
            $("#diap").css("display", "none");
			if(!popupIsShown)
                $('embed').css('visibility', 'visible');
        }
    );

    $(".navigationbalk").mousemove(function(e)
    {
        moveamount = e.pageX - 80;
        $('#diap').css("left", moveamount + "px");
        $('#diap #mainnav2').css("left", "-" + moveamount + "px")
        //$('#status').html(e.pageX +', '+ e.pageY);
    });

    // $("#mainnav li").hover(
    //			    function() {
    //			        $("ul", this).fadeIn("fast");
    //			        $(".diap").fadeIn("slow");
    //			    },
    //			    function() { }
    //		    );
    $(".enlarge").hover(
		function()
		{
		    $(this).addClass("showEnlarge");
		},
		function()
		{
		    $(this).removeClass("showEnlarge");
		}
	);
    // start: suckerfish
    if ($.browser.msie)
    {
        $("#mainnav2 li").hover(
                    function()
                    {
                        $(this).addClass("sfHover");
                    },
                    function()
                    {
                        $(this).removeClass("sfHover");
                    }
                );
    }
    //end: suckerfish

});    // end document ready

$(window).resize(function(){			  
	$("#diap #mainnav2").css("width", $(window).width());
});
function hideIframe() {
    answer = confirm("Sluit dit scherm alleen als u de bestelling heeft voltooid.\n\nKlik op 'ANNULEREN' om terug te gaan naar de het bestelproces,\nof op 'OK' om de ticketshop te sluiten.")
    
	if (answer !="0")
	{
	    pointer = 0;
	    orderURLs = new Array();
	    $('#mijnHFcontainer .uitvoering').each(function()
	    {
	        $(this).find('input')[0].checked = false;
	    });
	    $('.checkall').attr('checked', false);
	    assertKoopButtonColour();
	    
	    $(".containIframe").hide();
	    hideGreyout();

	    ophalenBookmarks();
	}
	return false;
}
function showGreyout(which) {
	// allover: bij aankondiging
	// dragover: bij drag naar mijnHF

    popupIsShown = true;
    
	$('embed').css('visibility', 'hidden');
	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$("#greyout").css("height", $(document).height() + "px");	
	} else {
		$("#greyout").css("height", $(document).height() + "px").css("position","fixed");	
	}
	$("#greyout").show();
}

function hideGreyout() {
    popupIsShown = false;
	$('embed').css('visibility', '');
	$("#greyout").attr("class","").addClass("greyout");
	$("#voorstellingsdetailcontainer").hide("slow");
	$("#greyout").hide();
}

function showGreyoutAllover() {
    popupIsShown = true;
	$('embed').css('visibility', 'hidden');
	$("#greyout").css("height", $(document).height() + "px").css("position","fixed");
    $("#greyout").addClass("allover");
    $("#greyout").show();
}

function showDetailPopup(show) {
    showGreyout();
	
    $("#spinner").show('fast');
    $.ajax({
        type: "GET",
        url: "Services/Voorstelling.aspx?show=" + show,
        success: fillDetail,
        error: function() {
            hideGreyout();
            $("#spinner").hide('fast'); 
        }
    });
}

function showDetailPopupVoorstelling(show, inArchief) {
    showGreyout();

    var page = "Voorstelling.aspx";

    if (inArchief)
        page = "ArchiefDetail.aspx";    

    $("#spinner").show('fast');
    $.ajax({
        type: "GET",
        url: "Services/" + page + "?production=" + show,
        success: fillDetail,
        error: function() {
            hideGreyout();
            $("#spinner").hide('fast');
        }
    });

}

function hideDetailPopup() {
    $("#voorstellingsdetailcontainer").hide();
    hideGreyout();
}

function showFotoverslag(setID, imageID) {
    if (!setID)
        return;

    showGreyout();

    var page = "Services/MediaBrowser.aspx" + "?set=" + setID;

    if( imageID && imageID > 0)
         page += "&afbeelding=" + imageID;

     $("#spinner").show('fast');
    
    $.ajax({
    type: "GET",
        url: page, 
        success: fillDetail,
        error: function() {
            hideGreyout();
            $("#spinner").hide('fast');
        }
    });
}

function fillDetail(e) {
    $("#voorstellingsdetailcontainer").show();
	
	$("#voorstellingsdetailcontainer").html(e);

    $(".foldout>h1").click(
        function() {
            ($(this).parent().hasClass("folded")) ? $(this).parent().removeClass("folded").addClass("unfolded") : $(this).parent().removeClass("unfolded").addClass("folded");
        }
    );

    var windowScroll = $(window).scrollTop();
   
    if (windowScroll < 100){
	    $("#voorstellingsdetail").css("top",windowScroll + (100 - windowScroll)+"px");
    } else {
	    $("#voorstellingsdetail").css("top",windowScroll + 20+"px");  
    }
	$("#greyout").css("height", $(document).height() + "px");
	$("#spinner").hide('fast');

	addthis.button(".addthis_button");
}

function slideSwitch() {
	
    var $active = $('#slideshow DIV.active');
    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');
    
    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');
    
    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
            
        });
    }
function slideBookmarks() {
	
	if ($('#mijnHFcontainer div.uitvoering').length > 1) {
		var $active = $('#mijnHFcontainer DIV.uitvoering.active');
		if ( $active.length == 0 ) $active = $('#mijnHFcontainer DIV.uitvoering:last');
		
	   
		var $next =  $active.next(".uitvoering").length ? $active.next(".uitvoering") : $('#mijnHFcontainer DIV.uitvoering:first');
		
	   
		$active.addClass('last-active');
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
				
			});
	}
}

function doSearch(q)
{
 if (q.length > 0) {
        return true;
    }
    else {
        return false;
    }
}

$(document).ready(function() {
    $('form a').each(function() {

        var b = this;

        if (b && typeof (b.click) == 'undefined') {
            b.click = function() {
                var result = true;
                if (b.onclick) result = b.onclick();
                if (typeof (result) == 'undefined' || result) {
                    eval(b.getAttribute('href'));
                }
            }
        }
    });
});
