// JavaScript Document

var $j = jQuery.noConflict();

$j(document).ready(function(){
	
	$j('a.accordionLink').each(function(index, domEle) {
		$j(domEle).click(function() {
			//document.title += $j(domEle).children('.submenu').attr('id')
			$j(domEle).next('div.submenu').slideToggle();
			
		});
	})
	
	$j('.button-hotel').click(function () {
		$j('.list-hotel').slideToggle();
		});
	
	
		
	 toggleBg();
	 showCurrentSubMenu();
	

	
});
function toggleBg(){
	
	setInterval(function() {
		$j('.button-application').addClass('alt');
		
		
	}, 2000);
	setTimeout(function() {
		setInterval(function() {
		$j('.button-application').removeClass('alt');
		
		
		}, 2000);
	}, 1000); 
	 
	
}

function getUrlVarsFrom(url, preventUnwantedVars) {
	var vars = [],
		hash;
	var hashes = url.slice(url.indexOf('?') + 1).split('#')[0].split('&');
	for (var i = 0; i < hashes.length; i++) {
		hash = hashes[i].split('=');
		if (preventUnwantedVars == 1) {
			if (hash[0] != 'lg' && hash[0] != 'objectid' && hash[0] != 'tabindex' && hash[0] != 'page' && hash[0] != 'keyword' && hash[0] != 'mediaid') {
				if (hash[0] == 'categoryid' && hash[1] == 0) {} else {
					vars.push(hash[0]);
					vars[hash[0]] = hash[1];
				}
			}
		} else {
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
	}
	return vars;
}

//MENU FUNCTIONS

function nrKeys(a) {
	var i = 0;
	for (key in a) {
		i++;
	}
	return i;
}

function compareAssociativeArrays(a, b) {
	if (a == b) {
		return true;
	}
	if (nrKeys(a) != nrKeys(b)) {
		return false;
	}
	for (key in a) {
		if (a[key] != b[key]) {
			return false;
		}
	}
	return true;
}


function showCurrentSubMenu() {

	//check for matches on menu
	$j("a.accordionLink").each(function (index, domEle) {
		if (
		compareAssociativeArrays(getUrlVarsFrom(window.location.href, 1), getUrlVarsFrom($j(domEle).attr('href'), 1)) ||
		(getUrlVarsFrom(window.location.href, 1)['tabid'] == '14' && getUrlVarsFrom($j(domEle).attr('href'), 1)['tabid'] == '34') ||
		(getUrlVarsFrom(window.location.href, 1)['tabid'] == '29' && getUrlVarsFrom($j(domEle).attr('href'), 1)['tabid'] == '34') ||
		(getUrlVarsFrom(window.location.href, 1)['tabid'] == '39' && getUrlVarsFrom($j(domEle).attr('href'), 1)['tabid'] == '34') ||
		(getUrlVarsFrom(window.location.href, 1)['tabid'] == '12' && getUrlVarsFrom($j(domEle).attr('href'), 1)['tabid'] == '34') ||
		(getUrlVarsFrom(window.location.href, 1)['tabid'] == '153' && getUrlVarsFrom($j(domEle).attr('href'), 1)['tabid'] == '34')
		
		
		) {
			

			$j(domEle).next('div.submenu').show();

		}
	})

}

