(function() {
	var Config = {
		Path: {
			de: ["/tv/danni-lowinski"],
			at: [],
			ch: []
		},
		Target: {
			de: "/interstitial",
			at: "/interstitial",
			ch: "/interstitial"
		},
		cookieLifeTime: 30*60*1000
	};
	
	var Cookie = {
		key: "SIMFlashIntro",
		isset: function(format) {
		  var result = true;
			if (document.cookie && document.cookie.indexOf(Cookie.key + "=") != -1) {
				var content = document.cookie.split(Cookie.key + "=")[1].split(";")[0];
				if (content.indexOf(format) > -1) {
				  result = true;
				} else {
				  result = false;
				}
			} else {
			  result = false;
			}
			Cookie.set(format);
			return result;
		},
		set: function(format) {
			var now = new Date();
			var expiry = new Date();
			expiry.setTime(now.getTime()+(Config.cookieLifeTime));
			/*expiry.setHours(0);
			expiry.setMinutes(0);
			expiry.setSeconds(0);*/
			var content = format;
			if (document.cookie && document.cookie.indexOf(Cookie.key + "=") != -1) {
				content = document.cookie.split(Cookie.key + "=")[1].split(";")[0];
				if (content.indexOf(format) == -1) {
					content += "," + format;						
				}
			};
			document.cookie = Cookie.key + "=" + content + "; expires=" + expiry.toGMTString() + "; path=/";
		}
	};
	
	Location = function(w) {
	  this.tld = w.location.hostname.split(".sat1.")[1];
	  this.path = w.location.pathname;
	};
	
	GETParam = function(p) {
	  this.getstring = "?";
	  for (var i = 0; i < p.length; i++) {
	    this.getstring += p[i] + "=";
	    switch (p[i]) {
	      case "title": 
	        this.getstring += document.getElementsByTagName("head")[0].getElementsByTagName("title")[0].innerHTML;
	        break;
	      case "format":
	        this.getstring += Config.Path[loc.tld][index];
	    };
	    this.getstring += "&";
	  };
	  this.toString = function() {
	    return this.getstring;
	  };
	};
	
	var Helper = {
	  posInArray: function(array, element) {
     for(var i=0; i<array.length; i++){
          if(array[i]===element){
             return i;
          }
       };
       return -1;
    },
    isPartOfArrayElement: function(array, element) {
     for(var i=0; i<array.length; i++){
          if(element.indexOf(array[i]) > -1){
             return i;
          }
       };
       return -1;
    }
  };
	
	var loc = new Location(window);
	var index = Helper.isPartOfArrayElement(Config.Path[loc.tld], loc.path);
	if (index > -1 &&
	  !Cookie.isset(Config.Path[loc.tld][index])) {
	    window.location.replace(Config.Target[loc.tld] + loc.path + new GETParam(["title", "format"]).toString()); 
	};
	
})();

/*
* Search Hack:
* Search results showed results from preprod and integration.
*
$(function() {
  if (window.location.pathname.indexOf("/gsa/search")==0) {
    $(".container_960").find("a").each(function(key, value) {
      var href = $(this).attr("href");
      try {
        href = href.split("www-origin.sat1").join("www.sat1");
        $(this).attr("href", href);
        if ($(this).attr("href").indexOf("-origin.sat1")!=-1) {
          $(this).parent().parent().parent().next().remove();
          $(this).parent().parent().parent().remove();
        }
      } catch (err) {}
    });
  }
});*/

/*
* Gallery Image Hack:
* Gallery images are scaled to a width of 620px but should not.
*/
/*$(function() {
  $(".image_gallery_extended img").width("auto");
});
*/


//legacy:
teasercount = function() {};
teaserpfad = "";

$(function() {
  $("embed").each(function() {
    if ($(this).attr("id") == "myCustomId") {
      var link = $(this).attr("flashvars").split("linkurl=")[1].split("&")[0];
      var img = $(this).attr("flashvars").split("pic=")[1].split("&")[0];
      var headline = $(this).attr("flashvars").split("headline=")[1].split("&")[0];
      var text = $(this).attr("flashvars").split("teasertext=")[1].split("&")[0];
      var linktext = $(this).attr("flashvars").split("linktext=")[1].split("&")[0];
      var html = '<div style="position:relative;width:180px;left:8px;" class="comedy_show compress topspace floatable">' +
        '<a onclick="" target="" href="'+link+'"><img width="180" height="110" alt=""' + 
        ' src="'+img+'"></a><br>' +
        '<div class="teaserstreifen-180"><h6 class="home">Video</h6><h6 class="channel">Video</h6><h6 class="format">Video</h6></div>' +
        '<h1><a onclick="" target="" href="'+link+'">'+headline+'</a></h1>' +
        '<p><a onclick="" target="" href="'+link+'">'+text+'</a></p>' +
        '<a class="linkstyle" onclick="" target="" href="'+link+'">&gt; '+linktext+'</a> </div>';
     
      $(this).parent().parent().html(html);
    }
  });
});
