﻿// ============  GLOBAL JQUERY PARAMS ===========
$(document).ready(function() {
	//do the following wether logged in to OW or not
	//
	//jquery for parsing url - used to highlitght main nav
	jQuery.url = function() { var segments = {}; var parsed = {}; var options = { url: window.location, 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*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/} }; var parseUri = function() { str = decodeURI(options.url); var m = options.parser[options.strictMode ? "strict" : "loose"].exec(str); var uri = {}; var i = 14; while (i--) { uri[options.key[i]] = m[i] || "" } uri[options.q.name] = {}; uri[options.key[12]].replace(options.q.parser, function($0, $1, $2) { if ($1) { uri[options.q.name][$1] = $2 } }); return uri }; var key = function(key) { if (!parsed.length) { setUp() } if (key == "base") { if (parsed.port !== null && parsed.port !== "") { return parsed.protocol + "://" + parsed.host + ":" + parsed.port + "/" } else { return parsed.protocol + "://" + parsed.host + "/" } } return (parsed[key] === "") ? null : parsed[key] }; var param = function(item) { if (!parsed.length) { setUp() } return (parsed.queryKey[item] === null) ? null : parsed.queryKey[item] }; var setUp = function() { parsed = parseUri(); getSegments() }; var getSegments = function() { var p = parsed.path; segments = []; segments = parsed.path.length == 1 ? {} : (p.charAt(p.length - 1) == "/" ? p.substring(1, p.length - 1) : path = p.substring(1)).split("/") }; return { setMode: function(mode) { strictMode = mode == "strict" ? true : false; return this }, setUrl: function(newUri) { options.url = newUri === undefined ? window.location : newUri; setUp(); return this }, segment: function(pos) { if (!parsed.length) { setUp() } if (pos === undefined) { return segments.length } return (segments[pos] === "" || segments[pos] === undefined) ? null : segments[pos] }, attr: key, param: param} } ();
	//highlight tab function
	var page = jQuery.url.segment(2);//get the section name from the url
	var path = "/en/home/"+ page +"/default.aspx";//set the var for the link that matches the parent page of that section
	$("#mainMenu a[href$='" + path + "']").addClass("current");//find that link in the mainmenu and apply 'current' class
	// initialize scrollable together with the navigator plugin for homepage
	if ($("#browsable").length) {
		$("#browsable").scrollable({ size: 4 }).navigator();
	}
 
	//travel tools rollover
	$("ul.ttools > li > a").bind("mouseenter",function(){
		$("#traveltools_title").text(this.innerHTML);
	}).bind("mouseleave",function(){
		$("#traveltools_title").text("Roll over the icons below");
	});
	//mega menu drop down
	function addMega() {
		$(this).addClass("hovering");
	}
	function removeMega() {
		$(this).removeClass("hovering");
	}
	var megaConfig = {
		interval: 100,
		sensitivity: 4,
		over: addMega,
		timeout: 100,
		out: removeMega
	};
	$("li.mega").hoverIntent(megaConfig)
	//default search field text
	var active_color = '#fff'; // Colour of user provided text
	var inactive_color = '#fff'; // Colour of default text
	$("input.default-value").css("color", inactive_color);
	var default_values = new Array();
	$("input.default-value").focus(function() {
		if (!default_values[this.id]) {
			default_values[this.id] = this.value;
		}
		if (this.value == default_values[this.id]) {
			this.value = '';
			this.style.color = active_color;
		}
		$(this).blur(function() {
			if (this.value == '') {
				this.style.color = inactive_color;
				this.value = default_values[this.id];
			}
		});
	});

	//only run these scripts when NOT logged in to OW
	if (typeof OneWeb.Admin === "undefined") {
		//add double arrows to links
		$(".menu_links > ul > li").prepend("&raquo ");
		$("a.more_link").append(" &raquo");
		//footer feeds tabs
		//$(".ins_forum_tabs > ul").tabs("#tab_blocks > div").tabs({ fx: { opacity: "toggle", effect: "fade", fadeOutSpeed: 2} });
		$("#ui-tabs").tabs({ fx: { opacity: "toggle", effect: "fade", fadeOutSpeed: 2} });
	}
	
	//do this only when logged in to OW
	if (typeof OneWeb.Admin != "undefined") {
        //set up travel widget
		$("#tmpl_cbtravel_planner").css({'display':'inline-block','width':'100px','height':'25px'});
		$("#tmpl_cbtravel_planner > a.language").css({'display':'inline-block','margin-left':'-145px'});
		$("#tmpl_cbtravel_planner > div.myItins").css({'margin-left':'-145px'});
		// setup mega menu for display when in admin view
        $("div.mainmenu").css("background-image", "none");
        $("ul#mainMenu > li.mega").addClass("admin");
        // setup footer feeds tabs for display when in admin view
        $("div.ins_forum_copy").css({ 'display': 'block', 'height': 'inherit', 'margin-bottom': '30px' });
    }
	
});//end document.ready

