$(document).ready(function(){
	if($('form').length != 0){
		$('form').css({'display':'block'}).attr('action','/fpp/index.php');
	}
	if($.browser.msie && $.browser.version <= 9){
		$('h1').each(function(){
			var shadowTxt = $(this).text();
			$(this).append('<span class="shadow">'+ shadowTxt +'</span>');
		});
		$('header p').each(function(){
			var shadowTxt = $(this).text();
			$(this).append('<span class="shadow">'+ shadowTxt +'</span>');
		});		
	}
	
	if($("a[target='_blank']")){
		$("a[target='_blank']").each(function(){
			var destination = $(this).attr('href');
			var temp = destination.split('/redirect/?url=')

			if(temp[1] != null){
				$(this).click(function(){
					window.open(temp[1]);
					return false;
				});
			}
		});
	}
	
});
jQuery(window).load(function(){
	if( $('body#home').length != 0 ){
		$("div.x").delay(1000).fadeOut(1000)
		
		$.fn.toggleTiles();
	}
});


/**
* 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)
* @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);

(function($){
	
	/* VERTICAL ALIGN RANDOM HEIGHT ELEMENTS (IMG) */
	$.fn.vAlign = function(){
		return this.each(function(i){
			var ah = $(this).height();
			var ph = $(this).parent().height();
			var mh = Math.ceil((ph-ah) / 2);
			$(this).css('margin-top', mh);
		});
	};
	
	/* CENTER FLOATED ELEMENTS (by default floated elements left align) */
	$.fn.cAlign = function(){
		return this.each(function(i){
			var aw = $(this).children().width();
			var pw = $(this).width();
			var mw = Math.ceil((pw-aw) / 2);
			$(this).css({'margin-left':mw});			
		});
	};
	
	$.fn.toggleTiles = function(){
		$('section').each(function(){
			$(this).hoverIntent({over:tileOVER, timeout:50, out:tileOUT})
		});
	};			
	
})(jQuery);

/* Need for HOVERSLIDE */
function tileOVER(){
	$(this).children('div.x').fadeIn(300);
}
function tileOUT(){
	$(this).children('div.x').fadeOut(2000);
}

/**
 * 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
 *
 *	$.cookie('the_cookie'); // get cookie
 *	$.cookie('the_cookie', 'the_value'); // set cookie
 *	$.cookie('the_cookie', 'the_value', { expires: 7 }); // set cookie with an expiration date seven days in the future
 *	$.cookie('the_cookie', '', { expires: -1 }); // delete cookie
*/

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;
    }
};
