/**
 * Common execution js
 * @author AK 
 *  
 * 
 */

function isEmpty(str) { if (typeof str == 'undefined' || str === null || str === '' || str == 0) { return true; } return false; }

// container for Peppered scripts
var P = {};

//parseUri 1.2.2
//(c) Steven Levithan <stevenlevithan.com>
//MIT License

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};


$(function() {
	$( "#tabs" ).tabs();
});


$(function(){
	
	Array.prototype.in_array =  function(search_term) {
	   for (var i = 0; i < this.length; i++) {
		  if (this[i] === search_term) {
		 return true;
	   }
	 }
   return false;
	}
	
	var currentMenuItem, currentSubMenuItem;
	var dropMenuHideTimeout, dropSubMenuHideTimeout, dropSubMenuShowTimeout, holdSubMenuTimeout;
	var hoveredMenuId, hoveredSubMenuId; // the items that are just hovered
	var holdSubMenu = false;
	var item;
	
	// dropmenu
	$("#menu .dropMenu").hide();
	$("#menu .dropMenuContainer").hover(function(){
		clearTimeout(dropMenuHideTimeout);
		if (hoveredMenuId && $(this).attr("id") != hoveredMenuId) {
			$('#'+hoveredMenuId).children(".dropMenu").hide();
		}
		$(this).children(".dropMenu").show();
						
	}, function(){
		//$("#menu .dropSubMenu").hide();
		currentMenuItem = $(this);
		hoveredMenuId = currentMenuItem.attr("id");
		dropMenuHideTimeout = setTimeout(function(){currentMenuItem.children(".dropMenu").hide()}, 500);
	});
	
	// dropsubmenu
	$("#menu .dropSubMenu").hide();
	$("#menu .dropSubMenuContainer").hover(function(){
		if (holdSubMenu) {
			// don't show this hovered submenu when another is just opened..
			itemId = $(this).attr("id");
			holdSubMenuTimeout = setTimeout(function(){clearHold(itemId)}, 400);
			return;
		}

		clearTimeout(dropSubMenuHideTimeout);
		clearTimeout(dropSubMenuShowTimeout);
		//$("#menu .dropSubMenu").hide();
		if (hoveredSubMenuId && $(this).attr("id") != hoveredSubMenuId) {
			$('#'+hoveredSubMenuId).children(".dropSubMenu").hide();
		}
		//$(this).children(".dropSubMenu").show();
		currentSubMenuItem = $(this);
		dropSubMenuShowTimeout = setTimeout(function(){showSubMenu(currentSubMenuItem)}, 180);
		//showSubMenu(currentSubMenuItem);
		//alert($(this).attr("id"));
		
	}, function(){
		currentSubMenuItem = $(this);
		hoveredSubMenuId = currentSubMenuItem.attr("id");
		//$(this).children(".dropSubMenu").slideUp();
		dropSubMenuHideTimeout = setTimeout(function(){currentSubMenuItem.children(".dropSubMenu").hide()}, 500);
	});
	 
	function showSubMenu(theSubMenu) {
		// show subMenu, don't hide it when user hovers over mainmenu item
		clearTimeout(dropSubMenuShowTimeout);
		$("#menu .dropSubMenu").hide(); // force all to hide
		theSubMenu.children(".dropSubMenu").show();
		holdSubMenu = true;
	}
	function clearHold(hoveredSubMenuId) {
		holdSubMenu=false;
		showSubMenu($('#'+hoveredSubMenuId));
		return;
		// if other than holded submenu...
		//if (hoveredSubMenu != currentSubMenuItem) {
		if (hoveredSubMenuId && hoveredSubMenuId != currentSubMenuItem.attr("id")) {
			currentSubMenuItem.children(".dropSubMenu").hide();
			$('#'+hoveredSubMenuId).children(".dropSubMenu").show();
		}
	}
	
	/**
	* meer speeldata
	* 
	*/

	$("#meerData").addClass('hidden');
	$('.meerDataAnchor').click(function() {		
		$('#meerData').toggleClass('hidden');
		$(this).toggleClass('toggleButtonHide'); 
		//if($(this).hasClass('toggled')) {
		//	$('#meerDataAnchor span').text('terug');	
		//} else {			
		//	$('#meerDataAnchor span').text('meer data');	
		//}							
	  	return false;
 	}); 

	/**
	 * Voorstellingen & Film list items
	 * 
	 */
	$('.highlight li').hover(function(){
		$(this).addClass('hover');
		$(this).find('a.leesMeer').addClass('hover');
	},function(){
		$(this).removeClass('hover');
		$(this).find('a.leesMeer').removeClass('hover');
	});
	$('.highlight li .txtLink').hover(function(){
		$(this).parents('li').find('a.leesMeer').removeClass('hover');
	},function(){
		$(this).parents('li').find('a.leesMeer').addClass('hover');
	});
	$('.highlight li').click(function(){
		sHref = $(this).find('a.leesMeer').attr('href');
		window.location.href = sHref;
	});	
	$('.highlight li input.txtLink').click(function(e){
		e.stopPropagation();
	});
	
	
	// calendar columns
	$("table.calendar tr.weekdays th a").mouseover( function() {
		var iIndex = $(this).parent().parent().children('th').index($(this).parent()[0]);
		$("table.calendar tr td:nth-child(" + (iIndex+1) + ") a").addClass('active');
	 });
	$("table.calendar tr.weekdays th a").mouseout( function() {
		var iIndex = $(this).parent().parent().children('th').index($(this).parent()[0]);
		$("table.calendar tr td:nth-child(" + (iIndex+1) + ") a").removeClass('active');
	 });
	 
	// calendar rows
	$("table.calendar th.week a").mouseover( function() {
		$(this).parents('tr').find('a').addClass('active') });
	$("table.calendar th.week a").mouseout( function() {
		$(this).parents('tr').find('a').removeClass('active') });

	$(".ticketsLink.bestellingBezig").click( function() {
		blnReturn =  confirm ("LET OP! U wilt een voorstelling kopen die al in de vrije verkoop is (alle voorstellingen t/m september 2008 en Alessandro Safina, Footloose, Sunset Boulevard, Joseph en High School Musical). Deze bestelling wordt via de site van Tickets.com afgehandeld. \nDaarnaast bent u ook voorstellingen van het nieuwe seizoen (vanaf 1 oktober 2008) via het bestel/e-mailformulier aan het reserveren. Om deze kaarten te kunnen reserveren dient u eerst uw bestelling van de kaarten in de vrije verkoop af te ronden. Vervolgens keert u terug naar de site van Theater aan de Parade en klikt u op \"winkelmandje\" bovenaan de pagina.");
		$("#uitlegVvkContainer").show("slow");
		return blnReturn;
	});
	
});

/* wordt de css van box-shadow gelezen */
function supportsBoxShadow() {
	var s = document.body.style;
	return s.WebkitBoxShadow !== undefined || s.MozBoxShadow !== undefined;
}



