 // JQUERY - CUSTOM.JS

$(document).ready(function() {		


	//*****************************************************************************************//	
	// HIDE CLASS SINCE WE HAVE JAVA ENABLED
	//*****************************************************************************************//

		// Since we have javascript enabled, then all classes with has javascript gets removed
		$('.has_javascript').hide();

	//*****************************************************************************************//	
	// PRESS BOX
	//*****************************************************************************************//
	
	var current_box_number = "01";

	$('.press_box').click(function(){
		
		// Get the number of the box
		var img_number = $(this).attr('id');
		var new_box_number = img_number.substr(img_number.length - 2);
	
		// Turn on that box's text
		$('#press_box_text_'+current_box_number).css('display', 'none');
		$('#press_box_text_'+new_box_number).css('display', 'inline');
		current_box_number = new_box_number;
		
	});
	
	//*****************************************************************************************//	
	// FADE IN - FADE OUT
	//*****************************************************************************************//
	
	// Microsoft has hard time with transparent PNG files, so fuck them
	if (!($.browser.msie))  {
	
	    // A - FADE IN           
  		var $javascript_note = $('#javascript_note');
  		var $top_footer_center = $('#top_footer_center');
  		var $middle_body = $('#middle_body');
  		var $middle_footer = $('#middle_footer');
  		var $bottom = $('#bottom_wrapper');
  		var $bottomline = $('#bottomline_wrapper');
		
		// The unload and .hide solve the flicker problem some browsers have.
   		$(window).bind("unload", function() {});
		$javascript_note.css("display","none");
  		$javascript_note.hide();
		$top_footer_center.css("display","none");
  		$top_footer_center.hide();
		$middle_body.css("display","none");
  		$middle_body.hide();
		$middle_footer.css("display","none");
  		$middle_footer.hide();
		$bottom.css("display","none");
  		$bottom.hide();
		$bottomline.css("display","none");
  		$bottomline.hide();
	
		// WAIT TILL THE DOM LOADS (images) BEFORE YOU fade 
		$(window).load(function(){
       		$javascript_note.fadeTo(500,1);
       		$top_footer_center.fadeTo(500,1);
       		$middle_body.fadeTo(500,1);
       		$middle_footer.fadeTo(500,1);
			$bottom.fadeTo(500,1);
			$bottomline.fadeTo(500,1);
  		});
		
		// B - FADE OUT (But not on class="ignorefade"
		// But if href is #, its not a redirect. So make a class "ignorefade" to ignore the fade
		$('a').click(function(event){	

			// Good example why you use this
			if (!($(this).hasClass("ignorefade"))) {
    	  		event.preventDefault();
       			linkLocation = this.href;
				$javascript_note.fadeTo(250,0);
				$top_footer_center.fadeTo(250,0);
				$middle_body.fadeTo(250,0);
				$middle_footer.fadeTo(250,0);
        		$bottom.fadeTo(250,0,redirectPage);
        		$bottomline.fadeTo(250,0,redirectPage);
			}
		});
	}
	
	function redirectPage() {
     	window.location = linkLocation;
  	} 

});
	
//*****************************************************************************************//	
// COOKIE PLUGIN
//*****************************************************************************************//
	
/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 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 (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};


