/**
 * @author m.winata
 * MMC - Agentur 
 */
jQuery.url=function(){var segments={};var parsed={};var options={url:window.location,strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};var parseUri=function(){str=decodeURI(options.url);var m=options.parser[options.strictMode?"strict":"loose"].exec(str);var uri={};var i=14;while(i--){uri[options.key[i]]=m[i]||""}uri[options.q.name]={};uri[options.key[12]].replace(options.q.parser,function($0,$1,$2){if($1){uri[options.q.name][$1]=$2}});return uri};var key=function(key){if(!parsed.length){setUp()}if(key=="base"){if(parsed.port!==null&&parsed.port!==""){return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/"}else{return parsed.protocol+"://"+parsed.host+"/"}}return(parsed[key]==="")?null:parsed[key]};var param=function(item){if(!parsed.length){setUp()}return(parsed.queryKey[item]===null)?null:parsed.queryKey[item]};var setUp=function(){parsed=parseUri();getSegments()};var getSegments=function(){var p=parsed.path;segments=[];segments=parsed.path.length==1?{}:(p.charAt(p.length-1)=="/"?p.substring(1,p.length-1):path=p.substring(1)).split("/")};return{setMode:function(mode){strictMode=mode=="strict"?true:false;return this},setUrl:function(newUri){options.url=newUri===undefined?window.location:newUri;setUp();return this},segment:function(pos){if(!parsed.length){setUp()}if(pos===undefined){return segments.length}return(segments[pos]===""||segments[pos]===undefined)?null:segments[pos]},attr:key,param:param}}();

jQuery(document).ready(function(){
	var cookieSchnitzeljagd = jQuery.cookieJar('schnitzeljagd');
	var cookieSchnitzeljagdGet = cookieSchnitzeljagd.get('isset');
	var currentUrl = window.location.href;
	var iframeLink = jQuery("#WNJaNatuerlichMasterPage_WNJaNatuerlichMasterPage_ucBanner_banner iframe").attr('src');
	var dontSet = 0;
	
	jQuery(".schnitzeljagd").each(function(){
		var href = jQuery(this).attr('href');
		jQuery(this).attr('href',href+"&siteUrl="+currentUrl);
		
	});
	
	if (jQuery.url.param('setcookie') == '1') {
		// Set Cookie
		cookieSchnitzeljagd.set('isset','1');
		jQuery("#WNJaNatuerlichMasterPage_WNJaNatuerlichMasterPage_ucBanner_banner iframe").attr('src','http://rewe.poweredby.mmcagentur.at/janatuerlich/schnitzeljagd_2010/sidebar.php?siteUrl='+currentUrl);
		jQuery("#WNJaNatuerlichMasterPage_WNJaNatuerlichMasterPage_ucBanner_banner iframe").attr('height','708');
		jQuery("#WNJaNatuerlichMasterPage_WNJaNatuerlichMasterPage_ucBanner_banner").attr('style','display:block;padding-top:0;background:none;');
	}
	else if (jQuery.url.param('setcookie') == '0') {
		
		cookieSchnitzeljagd.set('isset','0');
		dontSet = 1;
	}
	
	if(cookieSchnitzeljagdGet == 1 && dontSet == 0)
	{
		// Show Game instead of Facebook
		jQuery("#WNJaNatuerlichMasterPage_WNJaNatuerlichMasterPage_ucBanner_banner").attr('style','display:block;padding-top:0;background:none;');
		jQuery("#WNJaNatuerlichMasterPage_WNJaNatuerlichMasterPage_ucBanner_banner iframe").attr('height','708');
		jQuery("#WNJaNatuerlichMasterPage_WNJaNatuerlichMasterPage_ucBanner_banner iframe").attr('src','http://rewe.poweredby.mmcagentur.at/janatuerlich/schnitzeljagd_2010/sidebar.php?siteUrl='+currentUrl);
	}
	
	jQuery('.schnitzeljagd img').each(function(){
		var rand = Math.round(Math.random() * 2);
		
		if(rand == 1)
		{
			//jQuery(this).parent().attr('style','position:absolute;top:80px;left:520px;');
			jQuery(this).parent().attr('style','position:absolute;top:435px;left:480px;z-index:999;');
		}
		else if (rand == 2)
		{
			//jQuery(this).parent().attr('style','position:absolute;top:500px;left:480px;');
			jQuery(this).parent().attr('style','position:absolute;top:815px;left:440px;z-index:999;');
		}
	});
});
