/* Global javascript for RRG Celebrity Plates game */

$(document).ready(function(){

	//Preload CSS images
	$.preloadCssImages();

	// Initialise How to Play slider
	$('#coda-slider-1').codaSlider();

	// Initialise memory game
	jMemoGame.Play();
	$("#panel, #panel1,#panel2,#panel3,#panel4").css("height", $(document).height()); 
	
	//Various Panel fades
	$("#send-to-a-friend-link").click(function() { $("#panel3").fadeIn(250); });
	$("#send-to-a-friend-link2").click(function() { $("#panel3").fadeIn(250); });
	$("#start-page-flag").click(function() { $("#panel4").fadeIn(250); });
	$("#refer-sticky-link").click(function() { $("#friend-form").fadeIn(250); });
	$("#large-voucher-link").click(function() { $("#panel-sticky-block").fadeIn(250); });	
	
	//Send to a friend from Out of Time panel
	$("#panel2 a.send-to-a-friend").click(function() {
		$("#panel3").fadeIn(300);
		$(this).parents("#panel2").fadeOut(150);
	});
	
	//Close panel
	$(".closeButton").click(function() {
		$(this).parents(".modWindow").fadeOut(300);
		$(".formError").hide(); 
	});
	
	// Cookie Plugin
	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;
	    }
	};
	
	
});