/*******************************************************************************************************************************************************************
* Cookies for JQuery
*******************************************************************************************************************************************************************/
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;
};

/*******************************************************************************************************************************************************************
* Flash Cookie Analysis
*******************************************************************************************************************************************************************/
function ReadCookieData(outObjadv)
{

	obj = document.getElementById( 'outObj' );
	obj = obj.gfc();
	b = document.cookie;

	if ( ! b.match( /DEUSPIELT_ADV_LAYER=/ ) )
	{

		var a = new Date();
		a = new Date( a.getTime() + 1000*60*15 );

		ratio_sl = obj.sl === undefined ? 0 : obj.sl;
		ratio_dl = obj.dl === undefined ? 0 : obj.dl;

		ratio = ratio_sl / ratio_dl;
		// Default ad zone
		ad_zone = 1;

		if ( ( ratio > 0 && ratio <= 0.04 ) || ( ratio_sl == 0 && ratio_dl >= 20 ) )
		{
			ad_zone = 4;
		}
		else if ( ( ratio > 0.04 && ratio <= 0.1 ) || ( ratio_sl == 0 && ratio_dl >= 10 && ratio_dl < 20 ) )
		{
			ad_zone = 1;
		}
		else if ( ratio > 0.1 )
		{
			ad_zone = 2;
		}

		if ( ratio_dl == 0 && ratio_sl == 0 )
		{
			ad_zone = 3;
		}

		document.cookie = 'DEUSPIELT_ADV_LAYER=' + ad_zone + '; path=/; expires=' + a.toGMTString() + ';';

	}
}

/*******************************************************************************************************************************************************************
* Game Catalogue: Top 100 Carousel
*******************************************************************************************************************************************************************/
function mycarousel_itemLoadCallback(carousel, state)
{
    for ( var i = carousel.first; i <= carousel.last; i++ )
	{
        if ( carousel.has(i) )
		{
            continue;
        }
        if ( i > mycarousel_itemList.length )
		{
            break;
        }

        carousel.add( i, mycarousel_getItemHTML(mycarousel_itemList[i-1]) );
    }
};

/*******************************************************************************************************************************************************************
* JQuery functions and executions
*******************************************************************************************************************************************************************/
$(document).ready(function(){

	// GAN Billboard Zone
	/*
	if ($("#billboard_zone")[0])
	{
		$("#billboard_zone").show();
	}
	*/

	// Game Catalogue: Top 100 Carousel Hover-Effect
	$("body").delegate(".jcarousel-item-horizontal", "hover", function(){
		$(this).toggleClass("jcarousel-item-horizontal-active");
	});

});

