/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @return    The object (aka "this") that called hoverIntent, and the event object
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

/**
 * Preload plugin
*/
jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
};

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
/**
 * Page functions
*/
var aMenu = new Array("","01","131","132","137","148","136");

Array.prototype.inArray = function(mIndex) {
	for (var i in this) {
		if (this[i] === mIndex) {
			return i;
			break;
		};
	};
};

$.preloadImages("../images/01.jpg", "../images/02.jpg", "../images/03.jpg", "../images/04.jpg", "../images/05.jpg", "../images/06.jpg");
		$(document).ready(function(){
			var myMenu = $.cookie("headerImage");
			myMenu = aMenu.inArray(myMenu);
			if (myMenu == undefined) myMenu = 1;
			$("#headerImage").css("background-image", "url('./images/0" + myMenu + ".jpg')");
			$("#navWrapper ul li").hover(function() {
				$(this).addClass('ie6-hover');
			}, function() {
				$(this).removeClass('ie6-hover');
				});
			
			$("#navSecond ul li").hover(function() {
				$(this).css("background-image","url('')")
				$(this).addClass('ie6-hover');
			}, function() {
				$(this).css("background-image","url('./images/navigation/nav_bg_e.gif')")
				$(this).removeClass('ie6-hover');
				});
			
			$("#navWrapper ul li").click(function() {
				var myMenu = $(this).attr("id");
				if (myMenu != undefined) {
					$.cookie("headerImage", myMenu);
				};
				$("#headerImage").stop().css("opacity","1");
			})
			$("#navWrapper ul li").not("ul li ul li").hoverIntent(makeTall,makeShort);
			
			/*
			$("#mediabutton").click(function() {
				if ( $("#media").css("left") == "175px" ) {
					$("#media").animate({"left":-225},"slow",function(){ MediaPlayer.play() });
				} else {
					$("#media").animate({"left":175},"slow",function(){ MediaPlayer.pause() });
				};
			});
			*/
		});
		function makeTall(){
			$(this).children("ul").css("height","auto");
			var maxMenuHeight = parseInt( $(this).children("ul").height() );
			$(this).not("#01").children("ul").animate({"height":maxMenuHeight},200,function(){$(this).css("border-bottom","1px solid gray")});
			var myImage = $("#headerImage").css("background-image");
			myImage = myImage.substr(myImage.indexOf('0'), 2) * 1;
			var myMenu = $(this).attr("id");
			myMenu = aMenu.inArray(myMenu);
			if (myImage != myMenu && myMenu != undefined) {
				$("#headerImage").fadeOut("fast",function() { $("#headerImage").css("background-image", "url('./images/0" + myMenu + ".jpg')").fadeIn("slow") });
			};
		};
		function makeShort(){
			$(this).children("ul").animate({"height":0},200,function(){$(this).css("border-bottom","0")});
		};
