var floatmenu = false;
var activeLocation = false;
var play = false;
$(document).ready(function() {
	if(play) {
		return false;
	}
	
	$('#pane').jScrollPane({showArrows:true});
	$("a").live("dblclick", function(ev) {
		document.location.href = $(this).attr("href");
		return false;
	});
	$("a").live("click", function(ev) {
		play = true;
		ev.preventDefault();
		
		var goUrl = $(this).attr("href");
		tmp = parse_url(goUrl);
		skip = $(this).attr("gourl");
		
		if($(this).attr("target")) {
			window.open(goUrl);
			return false;
		}
		if(goUrl.indexOf("mailto") > -1) {
			document.location.href = goUrl;
			return false;
		}
		
		if(goUrl == "/"){ 
			$(".menu_div li").removeClass("active");			
			
			$("#home").addClass("active");
			
			
		}
		
		if((typeof(tmp.host) == "undefined" || tmp.host.indexOf("coolboxx") > -1) && typeof(skip) == "undefined") {
			$.get(goUrl, {"x": 1}, function(data) {
				if($(".jScrollPaneContainer").length > 0) {
					if($(".content").css("backgroundImage") != "none") {
						$("#bg1").css("backgroundImage", $(".content").css("backgroundImage"));
						$(".content").css("backgroundImage", "none")
					}
					$("#bg2").hide();
					$("#bg2").css("backgroundImage", $(".content", data).css("backgroundImage"));
					
					to = parseInt($("#pane", data).css("width"));
					from = parseInt($("#scroller").css("width"));
					if(to < from) {
						$("#bg2").fadeIn("fast", function() {
							$(".jScrollPaneContainer").fadeOut(400, function() {
								$("#footerimg").animate({"width": $("#pane", data).css("width")}, "slow");
								$("#scroller").animate({"width": $("#pane", data).css("width")}, "slow", function() {
									$("#scroller").html($("#scroller", data).html());
									
									v = $("#submenu", data).html();
									
									if($("#submenu", data).length > 0 && trim(v) != "") {										
										$("#submenu").show();
										$("#submenu").html($("#submenu", data).html());
									} else {
										$("#submenu").hide();
									}
									$("#bg1").css("backgroundImage", $("#bg2").css("backgroundImage"));
									
									$("#pane").jScrollPane({showArrows:true});
									$("#pane").hide();
									$("#pane").fadeIn();
									play = false;
								});
							});
						});
					} else {
						$(".jScrollPaneContainer").fadeOut(400, function() {
							$("#footerimg").animate({"width": $("#pane", data).css("width")}, "slow");
							$("#scroller").animate({"width": $("#pane", data).css("width")}, "slow", function() {
								$("#scroller").html($("#scroller", data).html());
								
								v = $("#submenu", data).html();
								
								if($("#submenu", data).length > 0 && trim(v) != "") {
									$("#submenu").show();
									$("#submenu").html($("#submenu", data).html());
								} else {
									$("#submenu").hide();
								}
								$("#bg2").fadeIn("fast", function() { 
									$("#bg1").css("backgroundImage", $("#bg2").css("backgroundImage"));
								});
								
								$("#pane").jScrollPane({showArrows:true});
								$("#pane").hide();
								$("#pane").fadeIn();
								play = false;
							});
						});
					}
				} else {
					document.location.href = goUrl;
				}
			});
		} else {
			document.location.href = goUrl;
			return true;
		}
	});
	
	$(".menu_div a").click(function() {
		$(".menu_div li").removeClass("active");
		$(this).parent("li").addClass("active");
	});		
		
});

 
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function parse_url (str, component) {
    // Parse a URL and return its components  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/parse_url
    // +      original by: Steven Levithan (http://blog.stevenlevithan.com)
    // + reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %          note: Based on http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
    // %          note: blog post at http://blog.stevenlevithan.com/archives/parseuri
    // %          note: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
    // %          note: Does not replace invaild characters with '_' as in PHP, nor does it return false with
    // %          note: a seriously malformed URL.
    // %          note: Besides function name, is the same as parseUri besides the commented out portion
    // %          note: and the additional section following, as well as our allowing an extra slash after
    // %          note: the scheme/protocol (to allow file:/// as in PHP)
    // *     example 1: parse_url('http://username:password@hostname/path?arg=value#anchor');
    // *     returns 1: {scheme: 'http', host: 'hostname', user: 'username', pass: 'password', path: '/path', query: 'arg=value', fragment: 'anchor'}
    var  o   = {
        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*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-protocol to catch file:/// (should restrict this)
        }
    };
    
    var m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
    uri = {},
    i   = 14;
    while (i--) {uri[o.key[i]] = m[i] || "";}
    // Uncomment the following to use the original more detailed (non-PHP) script
    /*
        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;
    */
 
    switch (component) {
        case 'PHP_URL_SCHEME':
            return uri.protocol;
        case 'PHP_URL_HOST':
            return uri.host;
        case 'PHP_URL_PORT':
            return uri.port;
        case 'PHP_URL_USER':
            return uri.user;
        case 'PHP_URL_PASS':
            return uri.password;
        case 'PHP_URL_PATH':
            return uri.path;
        case 'PHP_URL_QUERY':
            return uri.query;
        case 'PHP_URL_FRAGMENT':
            return uri.anchor;
        default:
            var retArr = {};
            if (uri.protocol !== '') {retArr.scheme=uri.protocol;}
            if (uri.host !== '') {retArr.host=uri.host;}
            if (uri.port !== '') {retArr.port=uri.port;}
            if (uri.user !== '') {retArr.user=uri.user;}
            if (uri.password !== '') {retArr.pass=uri.password;}
            if (uri.path !== '') {retArr.path=uri.path;}
            if (uri.query !== '') {retArr.query=uri.query;}
            if (uri.anchor !== '') {retArr.fragment=uri.anchor;}
            return retArr;
    }
}