/*
 * FlashObject embed :: 10-14-2004
 *
 * by Geoff Stearns (geoff@deconcept.com, http://blog.deconcept.com/)
 *
 * v1.0.1 - 10-15-2004
 *
 * Create and write a flash movie to the page, includes detection
 *
 * Usage:
 *
 *	myFlash = new FlashObject("path/to/swf.swf", "swfid", "width", "height", flashversion, "backgroundcolor");
 *	myFlash.altTxt = "Upgrade your Flash Player!";
 *	myFlash.addParam("wmode", "transparent");
 *	myFlash.addVariable("varname", "varvalue");
 *	myFlash.write();
 *
 */

FlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver || 6; // default to 6
	this.align = "middle"; // default to middle
	this.codebase = this.version +",0,0,0"; // fix cab download
	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	this.altTxt = "";
	this.bypassTxt = "";
	this.params = new Object();
	this.variables = new Object();
	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'high'); // default to high
	this.doDetect = getQueryParamValue('detectflash');
}

FlashObject.prototype.addParam = function(name, value) {
	this.params[name] = value;
}

FlashObject.prototype.getParams = function() {
    return this.params;
}

FlashObject.prototype.getParam = function(name) {
    return this.params[name];
}

FlashObject.prototype.addVariable = function(name, value) {
	this.variables[name] = value;
}

FlashObject.prototype.getVariable = function(name) {
    return this.variables[name];
}

FlashObject.prototype.getVariables = function() {
    return this.variables;
}

FlashObject.prototype.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    if (paramTags == "") {
        paramTags = null;
    }
    return paramTags;
}

FlashObject.prototype.getHTML = function() {
    var flashHTML = "";
    if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ this.codebase +'" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" />';
				flashHTML += '<param name="wmode" value="transparent" />';
        if (this.getParamTags() != null) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    else { // Everyone else
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" wmode="transparent" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs() != null) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    }
    return flashHTML;	
}


FlashObject.prototype.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) {
        variablePairs.push(name + "=" + escape(this.getVariable(name)));
    }
    if (variablePairs.length > 0) {
        return variablePairs.join("&");
    }
    else {
        return null;
    }
}

FlashObject.prototype.write = function(elementId) {
	if(detectFlash(this.version) || this.doDetect=='false') {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
		if (this.redirect != "") {
			document.location.replace(this.redirect);
		}
		document.write(this.altTxt +""+ this.bypassTxt);
	}		
}

function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x){
			if (x.description) {
				var y = x.description;
	   			flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
	} else {
		result = false;
	    for(var i = 15; i >= 3 && result != true; i--){
   			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
   			flashversion = i;
   		}
	}
	return flashversion;
}

function detectFlash(ver) {	
	if (getFlashVersion() >= ver) {
		return true;
	} else {
		return false;
	}
}

// get value of querystring param
function getQueryParamValue(param) {
	var q = document.location.search;
	var detectIndex = q.indexOf(param);
	if(q.length > 1 && detectIndex != -1) {
		return q.substring(q.indexOf("=", detectIndex)+1, q.indexOf("&", detectIndex));
	} else {
		return true;
	}
}





// IE hack for absolute positioning of Flash Element in IE5


if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	window.attachEvent("onload", fixIE5Bug);
}

function fixIE5Bug() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var posChange = (rslt != null && Number(rslt[1]) < 6.0);
	if (posChange){
		document.getElementById("boj").style.left = "0px";
		document.getElementById("boj").style.top = "0px";
	}
}



function openComp(linkUrl) {
		window.open(linkUrl, "Competition", "height=500,width=450,titelbar=1,channelmode=0,screenX=0,left=0,screenY=0,top=0,hotkeys=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0");
		return false;
}

function openFullWindow(theURL) { 
	window.open(theURL);
	return false;
}


function openBrWindow(theURL,winName,features) { 
	window.open(theURL,winName,features);
	return false;
}

function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn); 
		return r;
	} else {
		return false;
	}
}

var ofrW = 168;
var ofrInterval = 2500;
var extendMaxa = 4;
var ofrTotal = 0;

fx.Background = Class.create();
fx.Background.prototype = Object.extend(new fx.Base(), {
	initialize: function(el, options) {
		this.el = $(el);
		this.setOptions(options);
		this.now = 0;
	},
	increase: function() {
		this.el.style.marginLeft = this.now + "px";						
	},
	scroll: function(howMuch){
			
		this.clearTimer();

		// calculate the width of elements, including padding/border								
		var scroll_limit = this.el.offsetWidth - this.el.parentNode.offsetWidth + (ofrW);
		
		//if (((this.now + howMuch) <= 0) && ((this.now + howMuch) >= -(Math.abs(howMuch) + scroll_limit))) {
		if (((this.now + howMuch) <= 0) && ((this.now + howMuch)>=-(Math.abs(howMuch) + (ofrTotal*ofrW)))){
			this.custom(this.now, this.now + howMuch);
		}else{
			//this.custom(this.now, 0);

			if((this.now==0)&&howMuch>0){
				this.el.style.marginLeft = -(ofrTotal*ofrW);
				this.now = -(ofrTotal*ofrW);
			}else{
				this.el.style.marginLeft = -ofrW;
				this.now = -ofrW;
			}
			this.custom(this.now, this.now + howMuch);
		}
		clearInterval(autoScr);
		autoScr = setInterval(autoScroll, ofrInterval);
	}
});


function autoScroll(){
	myNewEffect.scroll(-ofrW);
}

function stp(){
	clearInterval(autoScr);
}

function srt(){
	autoScr = setInterval(autoScroll, ofrInterval);
}


function getTDs() {
	var tds = document.getElementById('campaignoffers').getElementsByTagName('TD');
	maxa = tds.length - extendMaxa;
	for (var i = 0; i < tds.length; i++) {
		tds[i].id = 'content' + (i+1);
		if(i>=(tds.length-extendMaxa)){
			tds[i].innerHTML = tds[(i-(tds.length-extendMaxa))].innerHTML;
		}else{
			ofrTotal = i+1;
		}
	}
}


window.onload = function() {
	if(document.getElementById('campaignoffers')){
		myNewEffect = new fx.Background('campaignoffers', {duration: 300});
		autoScr = setInterval(autoScroll, 2500);
		getTDs();
	}
}
