iad = {version: '1.5.9'};

iad.apply = function(o, c, defaults){
    if(defaults){
        // no "this" reference for friendly out of scope calls
        iad.apply(o, defaults);
    }
    if(o && c && typeof c == 'object'){
        for(var p in c){
            o[p] = c[p];
        }
    }
    return o;
};

(function(){
    var idSeed = 0;
    var ua = navigator.userAgent.toLowerCase();

    var isStrict = document.compatMode == "CSS1Compat",
        isOpera = ua.indexOf("opera") > -1,
        isChrome = ua.indexOf("chrome") > -1,
        isSafari = !isChrome && (/webkit|khtml/).test(ua),
        isSafari3 = isSafari && ua.indexOf('webkit/5') != -1,
        isIE = !isOpera && ua.indexOf("msie") > -1,
        isIE7 = !isOpera && ua.indexOf("msie 7") > -1,
        isIE8 = !isOpera && ua.indexOf("msie 8") > -1,
		isIE9 = !isOpera && ua.indexOf("msie 9") > -1,
        isGecko = !isSafari && !isChrome && ua.indexOf("gecko") > -1,
        isGecko3 = isGecko && ua.indexOf("rv:1.9") > -1,
        isBorderBox = isIE && !isStrict,
        isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
        isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
        isAir = (ua.indexOf("adobeair") != -1),
        isLinux = (ua.indexOf("linux") != -1),
        isSecure = window.location.href.toLowerCase().indexOf("https") === 0,
        isIPad = navigator.userAgent.match(/iPad/i) != null,
        isIPhone = (navigator.userAgent.match(/iPod/i) != null || navigator.userAgent.match(/iPhone/i) != null);

        // remove css image flicker
	if(isIE && !isIE7){
        try{
            document.execCommand("BackgroundImageCache", false, true);
        }catch(e){}
    }
	
    iad.apply(iad, {
        isStrict : isStrict,
        isSecure : isSecure,
        isReady : false,
        isOpera : isOpera,
        isChrome : isChrome,
        isSafari : isSafari,
        isSafari3 : isSafari3,
        isSafari2 : isSafari && !isSafari3,
        isIE : isIE,
        isIE6 : isIE && !isIE7 && !isIE8,
        isIE7 : isIE7,
        isIE8 : isIE8,
		isIE9 : isIE9,
        isGecko : isGecko,
        isGecko2 : isGecko && !isGecko3,
        isGecko3 : isGecko3,
        isBorderBox : isBorderBox,
        isLinux : isLinux,
        isWindows : isWindows,
        isMac : isMac,
        isAir : isAir,
        isIPad : isIPad,
        isIPhone : isIPhone,
        
		isArray : function(v){
			return v && typeof v.length == 'number' && typeof v.splice == 'function';
		},

		isDate : function(v){
			return v && typeof v.getFullYear == 'function';
		},
        
        emptyFn : function(){},

        applyIf : function(o, c){
            if(o && c){
                for(var p in c){
                    if(typeof o[p] == "undefined"){o[p] = c[p];}
                }
            }
            return o;
        },
        
        extend : function(){
            // inline overrides
            var io = function(o){
                for(var m in o){
                    this[m] = o[m];
                }
            };
            var oc = Object.prototype.constructor;

            return function(sb, sp, overrides){
                if(typeof sp == 'object'){
                    overrides = sp;
                    sp = sb;
                    sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
                }
                var F = function(){}, sbp, spp = sp.prototype;
                F.prototype = spp;
                sbp = sb.prototype = new F();
                sbp.constructor=sb;
                sb.superclass=spp;
                if(spp.constructor == oc){
                    spp.constructor=sp;
                }
                sb.override = function(o){
                    iad.override(sb, o);
                };
                sbp.override = io;
                iad.override(sb, overrides);
                sb.extend = function(o){iad.extend(sb, o);};
                return sb;
            };
        }(),

        override : function(origclass, overrides){
            if(overrides){
                var p = origclass.prototype;
                for(var method in overrides){
                    p[method] = overrides[method];
                }
                if(iad.isIE && overrides.toString != origclass.toString){
                    p.toString = overrides.toString;
                }
            }
        },
        
        namespace : function(){
            var a=arguments, o=null, i, j, d, rt;
            for (i=0; i<a.length; ++i) {
                d=a[i].split(".");
                rt = d[0];
                eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
                for (j=1; j<d.length; ++j) {
                    o[d[j]]=o[d[j]] || {};
                    o=o[d[j]];
                }
            }
        }
    });

    // in intellij using keyword "namespace" causes parsing errors
    iad.ns = iad.namespace;
})();

iad.ns("iad", "iad.util");

iad.util.JSON = new (function(){
    var useHasOwn = !!{}.hasOwnProperty;

    // crashes Safari in some instances
    //var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;

    var pad = function(n) {
        return n < 10 ? "0" + n : n;
    };

    var m = {
        "\b": '\\b',
        "\t": '\\t',
        "\n": '\\n',
        "\f": '\\f',
        "\r": '\\r',
        '"' : '\\"',
        "\\": '\\\\'
    };

    var encodeString = function(s){
        if (/["\\\x00-\x1f]/.test(s)) {
            return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                var c = m[b];
                if(c){
                    return c;
                }
                c = b.charCodeAt();
                return "\\u00" +
                    Math.floor(c / 16).toString(16) +
                    (c % 16).toString(16);
            }) + '"';
        }
        return '"' + s + '"';
    };

    var encodeArray = function(o){
        var a = ["["], b, i, l = o.length, v;
            for (i = 0; i < l; i += 1) {
                v = o[i];
                switch (typeof v) {
                    case "undefined":
                    case "function":
                    case "unknown":
                        break;
                    default:
                        if (b) {
                            a.push(',');
                        }
                        a.push(v === null ? "null" : iad.util.JSON.encode(v));
                        b = true;
                }
            }
            a.push("]");
            return a.join("");
    };

    this.encodeDate = function(o){
        return '"' + o.getFullYear() + "-" +
                pad(o.getMonth() + 1) + "-" +
                pad(o.getDate()) + "T" +
                pad(o.getHours()) + ":" +
                pad(o.getMinutes()) + ":" +
                pad(o.getSeconds()) + '"';
    };

    /**
     * Encodes an Object, Array or other value
     * @param {Mixed} o The variable to encode
     * @return {String} The JSON string
     */
    this.encode = function(o){
        if(typeof o == "undefined" || o === null){
            return "null";
        }else if(iad.isArray(o)){
            return encodeArray(o);
        }else if(iad.isDate(o)){
            return iad.util.JSON.encodeDate(o);
        }else if(typeof o == "string"){
            return encodeString(o);
        }else if(typeof o == "number"){
            return isFinite(o) ? String(o) : "null";
        }else if(typeof o == "boolean"){
            return String(o);
        }else {
            var a = ["{"], b, i, v;
            for (i in o) {
                if(!useHasOwn || o.hasOwnProperty(i)) {
                    v = o[i];
                    switch (typeof v) {
                    case "undefined":
                    case "function":
                    case "unknown":
                        break;
                    default:
                        if(b){
                            a.push(',');
                        }
                        a.push(this.encode(i), ":",
                                v === null ? "null" : this.encode(v));
                        b = true;
                    }
                }
            }
            a.push("}");
            return a.join("");
        }
    };

    /**
     * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError.
     * @param {String} json The JSON string
     * @return {Object} The resulting object
     */
    this.decode = function(json){
        return eval("(" + json + ')');
    };
})();
/**
 * Shorthand for {@link Ext.util.JSON#encode}
 * @param {Mixed} o The variable to encode
 * @return {String} The JSON string
 * @member Ext
 * @method encode
 */
iad.encode = iad.util.JSON.encode;
/**
 * Shorthand for {@link Ext.util.JSON#decode}
 * @param {String} json The JSON string
 * @return {Object} The resulting object
 * @member Ext
 * @method decode
 */
iad.decode = iad.util.JSON.decode;


//random id
var randId;
var rand = 1;	//random id to avoid caching of old files
var timeout;

//default domain/ location
var hostDomain;
var hostLocation;
//os
var os;
//if vms is true dont do a domain check
var vms = true;
//environment the api grabs all the assets from (local / testing / staging / bigpondvideo / iad.bigpondvideo
var environment = "bigpondvideo";
var container = "flash";
//ajax communicaton class
var misc;
var playSchedule;
var liveAsset;

//object instances
var iadWidgetInstance;
var iadPlayerInstance;
var iadChannelInstance;
var iadCarouselInstance;
var iadCarouselExtInstance;
var iadLbInstance = {};
var iadLbExtInstance = {};
var iadHtmlInstance;
var iadHtml5Instance;
var flashCom;

//divs of modules
var widgetApiDiv;
var targetDiv;
var targetExtDiv = [];
var targetExtDiv1 = null;
var targetExtDiv2 = null;
var targetCarouselDiv;
var targetLbDiv;
var containerDiv;
var containerExtDiv = [];
var containerExtDiv1 = null;
var containerExtDiv2 = null;
var containerCarouselDiv;
var containerLbDiv;
var playerDiv;
var channelDiv;
var carouselDiv;
var carouselExtDiv;
var lbDiv;
var lbExtDiv;
var htmlDiv;
var hideDiv;

var totalModuleAssetCount;
var loadedModuleAssetCount;

var widgetParams;
var initContentObj;
var lightBoxInt;

var carousel;


function iadOnLoad(){}

iadOnLoad.widget = function(){
	iadWidgetInstance.init();
};
iadOnLoad.player = function(){
	iadPlayerInstance.init();
};
iadOnLoad.carousel = function(){
	//alert("iadOnLoad.carousel")
	iadCarouselInstance.init();
	if(iadCarouselExtInstance)
		iadCarouselExtInstance.init();
};
iadOnLoad.lb = function(){
	iadLbInstance.init();
	if(iadLbExtInstance)
		iadLbExtInstance.init();
};
iadOnLoad.html = function(){
	iadHtmlInstance.init();
};




if (!window.iad)
	window.iad = {};
	


function getStyle(el, cssprop){
    

}



var IadWidgetObject = function(widgetId, initOnLoad, metaData) 
{
	iadWidgetInstance = this;

        //check if params exists
	if(widgetId == undefined || widgetId == -1){
		return;
	}else{
		this.widgetId = widgetId;
		this.metaData = metaData;
		
		//check the environment
		if(typeof(iadEnvironment) == "string"){
			environment = iadEnvironment;
		}else if(typeof(iVideoEnvironment) == "string"){
			environment = iVideoEnvironment;
		}

		//set the timeout
		timeout = (typeof(iadTimeout) == "number") ? iadTimeout*1000 : 10000;
		
		//check if environment gets overwritten by th url
		var urlEnvironment = checkEnvironment();
		var urlWidgetId = checkWidgetId();
		if(urlEnvironment != "" && urlWidgetId != -1){
			environment = urlEnvironment;
			this.widgetId = urlWidgetId;
		}
		
		if(initOnLoad){
			//init player on page loaded
			if(window.addEventListener)
				window.addEventListener("load", iadOnLoad.widget, false);
			else if(window.attachEvent) window.attachEvent("onload", iadOnLoad.widget);
			else window.onload = iadOnLoad.widget;
		}else{
			//init player on user command
			this.init(widgetId, metaData);
		}
	}
};


IadWidgetObject.prototype =
{
	init: function(){

		vms = false;
		//create metadata if null
		if(this.metaData == undefined)
			this.metaData = {};

		hostDomain = location.hostname;
		hostLocation = encodeURIComponent(location.toString().split("?")[0], "UTF-8");
		
		this.metaData['location'] = hostLocation;
		this.metaData['widgetId'] = this.widgetId;
		this.metaData['debug'] = checkDebug();
		this.metaData['randId'] = randId = Math.ceil(Math.random()*1000);
		this.metaData['domain'] = getDomain();
		
		//this.createFlashCom(true);
		
		if(FlashInstalled() && !checkContainer()){
			this.createFlashCom(true);
		}
		else{
                        if(iadHtml5Instance){
                            misc = new nv.player.ClassInterface('Miscellaneous');
                            misc.doCall('getWidgetParams', this.metaData, {
                                            onFinish: iadWidgetInstance.handlerOnSuccess,
                                            scope: iadWidgetInstance
                            });
                        }
                        else{
                            addJavascript(getDomain() + "App/InfinityPlayer/Js/html5_player.js?rand="+randId, 'head');
                        }
		}
	},
	
	
	
	
	handlerOnSuccess: function(params){

		if(params == null && widgetParams == null)
			return;
		else if(params != null && widgetParams == null)
			widgetParams = clone(params);
		else
			params = clone(widgetParams);
			
		this.params = params;

        if(iad.isIPad || iad.isIPhone || checkContainer())
			container = params['widget']['container']['type'] = "html5";


                //check for for total module count
                totalModuleAssetCount = 0;
                if(typeof(params['widget']) == 'object'){
                    if(params['widget']['player'] != null){
                        totalModuleAssetCount++;
                        if(params['widget']['player']['showTitle'] == '1' || params['widget']['player']['showUnmetered'] == '1')
                                    totalModuleAssetCount += 1;
                        if(params['widget']['player']['showDescription'] == '1')
                                    totalModuleAssetCount += 1;
                    }
                    if(params['widget']['channel'] != null){
                        totalModuleAssetCount++;
                    }
                    if(params['widget']['carousel'] != null){
                        totalModuleAssetCount++;
                    }
                    if(params['widget']['leavebehind'] != null){
                        totalModuleAssetCount++;
                    }
                }
                if(typeof(params['external']) == 'object'){
                    for(var i=0; i<params['external'].length; i++)
                        totalModuleAssetCount++;
                }


		if(typeof(params['widget']) == 'object')	
			this.createWidget(params['widget']);

		if(typeof(params['external']) == 'object'){
			if(this.widgetId == 315){
				if(params['external'][0])
					params['external'][0]['leavebehind']['targetArea'] = "AdArea04";
				if(params['external'][1])
					params['external'][1]['leavebehind']['targetArea'] = "AdArea05";
			}
			for(var i=0; i<params['external'].length; i++){
				this.createExternal(params['external'][i], i);
			}
		}
	}, 
	
	
	clearWidget: function(){
                var moduleDiv;

		if(targetDiv){
			if(containerDiv){
				for(var i=containerDiv.childNodes.length-1; i>=0; i--)
				{
					moduleDiv = containerDiv.childNodes[i];
                                        for(var j=moduleDiv.childNodes.length-1; j>=0; j--)
                                        {
                                            moduleDiv.removeChild(moduleDiv.childNodes[j]);
                                        }
                                        containerDiv.removeChild(moduleDiv);
				}
				targetDiv.removeChild(containerDiv);
				containerDiv = null;
                        }
			targetDiv = null;
		}
		
		
		if(targetExtDiv.length != 0){
			for(var j=containerExtDiv.length-1; j>=0; j--)
			{
				for(i=containerExtDiv[j].childNodes.length-1; i>=0; i--)
				{
					moduleDiv = containerExtDiv[j].childNodes[i];
                                        for(var h=moduleDiv.childNodes.length-1; h>=0; h--)
                                        {
                                            moduleDiv.removeChild(moduleDiv.childNodes[h]);
                                        }
                                        containerExtDiv[j].removeChild(containerExtDiv[j].childNodes[i]);
				}
			}
			containerExtDiv = [];
			
			for(var j=targetExtDiv.length-1; j>=0; j--)
			{
				for(i=targetExtDiv[j].childNodes.length-1; i>=0; i--)
				{
					targetExtDiv[j].removeChild(targetExtDiv[j].childNodes[i]);
				}
			}
			targetExtDiv = [];
		}
		
		if(FlashInstalled() && !checkContainer()){
			if(widgetApiDiv){
				document.body.removeChild(widgetApiDiv);
				widgetApiDiv = null;
				if(flashCom)
					flashCom = null;
			}
		}

                randId = Math.ceil(Math.random()*1000);
                if(this.metaData)
                    this.metaData['randId'] = randId;
	},
	
	
	
	createFlashCom: function(init){
		//cerate div for swf listener on client side
		widgetApiDiv = document.createElement("DIV");
		widgetApiDiv.id = "widgetApiDiv";
		setCssStyle(widgetApiDiv, "position", "absolute");
		setCssStyle(widgetApiDiv, "display", "block");
		setCssStyle(widgetApiDiv, "left", "0");
		setCssStyle(widgetApiDiv, "zIndex", "2000");
		setCssStyle(widgetApiDiv, "width", "100");
		setCssStyle(widgetApiDiv, "height", "100");
		document.body.appendChild(widgetApiDiv);

                if(this.metaData == null)
                    this.metaData = {};

		var swfWidth = "\"0\"";
		var swfHeight = "\"0\"";
		if(this.metaData['debug'] == '1'){
				swfWidth = "\"75\"";
				swfHeight = "\"75\"";
		}else{
				setVisibility("widgetApiDiv", false);
		}
		
		this.metaData['initWidget'] = (init) ? '1' : '0';
		
		//create the swf and add to dom
		var flashVars = '';
		for(var i in this.metaData){
			if(flashVars != '')
				flashVars += '&';
			
			flashVars += i + '=' + this.metaData[i];
		}

		var swfUrl = getDomain()+"App/InfinityPlayer/Flash/flashCom.swf?rand="+rand;
		flashCom = createSwf(widgetApiDiv, swfUrl, swfWidth, swfHeight, '000000', 'flashObjCr4', flashVars, false);
	},
	
	
	createWidget: function(params)
	{
		//check if params are defined
		if(params['container'] == null){
			return;	
		}
		
		//check the environment
		if(typeof(iadEnvironment) == "string"){
			if(environment != iadEnvironment)
				environment = iadEnvironment;
		}

		
		if(randId == undefined)
			randId = Math.ceil(Math.random()*1000);
		

		//set the target div of the parent side
		if(targetDiv == null)
			targetDiv = document.getElementById(params['container']['targetDiv']);


		//if site not built in vms
		if(!vms && params['container']['allowDomain'] != null && params['container']['allowDomain'] != undefined && params['container']['allowDomain'] != ''){
			//check if domain is allowed in vms
			if(!checkDomain(eval(params['container']['allowDomain']))){
				p = document.createElement("P");
				text = document.createTextNode("Sorry, your domain is NOT valid");
				p.appendChild(text);
				targetDiv.appendChild(p);
				return;
			}
		}
		
		
		//temp ----------
		//params['container']['lightBox'] = '1';
		//params['player']['adMessage'] = 'Advertisement: your video starts in _time_ seconds';
		//params['player']['radio'] = '1';
		//params['player']['radioLogo'] = 'http://testing.iad.netventures.com.au/temp/radioLogo.jpg';
		//params['player']['contentId'] = '220944';
		
//		params['channel']['style'] = '1';
//		params['channel']['showLink'] = '1';
//		params['channel']['linkTitle'] = 'TV GUIDE';
//		params['channel']['linkImg'] = 'http://iad/dev/channel_img.jpg';
//		params['channel']['linkUrl'] = 'http://www.google.com';
//		params['channel']['linkPos'] = 'Inline';
//		params['channel']['clipWidth'] = '66';
//		params['channel']['clipHeight'] = '66';
//		params['channel']['marginX'] = '3';
//		params['channel']['marginY'] = '5';
//		params['channel']['clipsTotal'] = '6';
//		params['channel']['width'] = '500';
//		//params['channel']['targetLevel'] = 'VIDEOS.NEWS';
//		params['channel']['activeColor'] = 'ff0000_sep_00ff00_sep_0000ff';
//		//
//
//		delete params['player'];
		//delete params['carousel'];
		//params['player']['cStyle'] = '9';
		//params['player']['externalAds'] = '1';
		//params['player']['externalInterval'] = '600';
		//params['player']['height'] = '240';
		//params['player']['silverlight'] = '1';
		//params['player']['liveBwOption'] = '2';
		//params['player']['wmv'] = '0';
		//params['player']['flv'] = '1';
		//params['player']['stf'] = '1';
		//params['player']['showUnmetered'] = '0';
		//params['player']['showBw'] = '1';
		//params['player']['bClickThrough'] = 'http://www.google.com';
		//params['player']['showDescription'] = '1';
		//params['player']['descriptionHeight'] = '60';
		//params['player']['dFontSize'] = '11';
		//params['player']['dFontColor'] = 'ffffff';
		//params['player']['feedbackUrl'] = 'http://bigpondvideo.com/help.php';
		
		
		
		//params['carousel']['autoStart'] = '0';
		//params['carousel']['marginY'] = '2';
		//params['carousel']['playlist'] = '0';
		//params['carousel']['width'] = '480';
		//params['carousel']['height'] = '88';
		//params['carousel']['imageWidth'] = '100';
		//params['carousel']['imageHeight'] = '55';
		//params['carousel']['clipWidth'] = '100';
		//params['carousel']['clipHeight'] = '83';
		//params['carousel']['fontColor'] = 'ffffff';
		//params['carousel']['activeColor'] = '029acb';
		//params['carousel']['showTooltip'] = '1';
		//params['carousel']['style'] = '9';
		//params['carousel']['carouselTarget'] = 'lightbox';
		//delete params['carousel']['tabs'];
		
		//params['carousel']['showTooltip'] = '0';
		
		//for SBS 	
		
		/*if(this.widgetId == 200){
			params['leavebehind'] = {};
			params['leavebehind']['xPos'] = '2';
			params['leavebehind']['yPos'] = '-25';
			params['leavebehind']['width'] = '653';
			params['leavebehind']['height'] = '404';
			
			params['leavebehind']['targetArea'] = 'AdArea03';
			params['leavebehind']['targetDiv'] = 'take_over_ad';
			//params['leavebehind']['initBanner'] = 'http://testing.iad.netventures.com.au/temp/SBS_takeover.swf';
			//params['leavebehind']['initUrl'] = 'http://iad.tv';
	
			if(params['leavebehind']['targetArea'] == 'AdArea03'){
				params['container']['height'] = 249;	
			}	
		}*/
		if(this.widgetId == 4){
			params['player']['muted'] = '1';
		}

		if(this.widgetId == 12){
			params['leavebehind']['floating'] = '1';
		}

		if(this.widgetId == 19){
			params['container']['windowless'] = '0';
			params['container']['lightBox'] = '1';
                        params['container']['allowOverlays'] = '0';
		}

		if(this.widgetId == 21){
			if(params['player'])
				params['player']['allowScrubbing'] = '1';
		}
		
		//FOR BIGPOND AFL DEMO 20101214
		if(this.widgetId == 29){
			if(params['player'])
				params['player']['cStyle'] = '5';
				
			if(params['carousel'])
				params['carousel']['style'] = '3';
		}
		
		
		//AFL FANTASY DEMO
		if(this.widgetId == 30 || this.widgetId == 31){
			params['carousel']['style'] = '9';
			params['carousel']['carouselTarget'] = 'lightbox';
		}
		//temp --------
		
		//fix show band width for old players
		if(params['player'])
			if(params['player']['live'] == '1')
				params['player']['showBw'] = '1';
		
		//if no controls are shown set style to 1
		if(params['player']){
			if(params['player']['controls'] == 'none' || params['player']['controls'] == 'external')
				params['player']['cStyle'] = '1';
		}
		
		
		//style 7 and 8 don't support silverlight
		if(params['player']){
			if(params['player']['cStyle'] == '7' || params['player']['cStyle'] == '8'){
				params['player']['wmv'] = '0';
				params['player']['flv'] = '1';
			}
		}
		

		
		
		//remove null and empty strings
		for(var i in params){
			if(i != 'serviceName'){
				for(var j in params[i]){
					if(params[i][j] == "" || params[i][j] == null)
						delete params[i][j];
				}	
			}	
		}

                
		//if light box is being used load essential js and css file
		if(params['container'])
			this.lightBoxLoaded = (params['container']['lightBox'] != '' && params['container']['lightBox'] != '0' && params['container']['lightBox'] != null) ? true : false;

		if(this.lightBoxLoaded)
			this.lightBoxWidgetId = (params['container']['lightBox'] != '1') ? params['container']['lightBox'] : 20;


		//fix for allow overlays
		if(params['container'])
			params['container']['allowOverlays'] = (params['container']['allowOverlays']) ? params['container']['allowOverlays'] : '1';

		//create divs
		this.createDivs(params, targetDiv);

		loadedModuleAssetCount = 0;
		widgetLoaded = false;
		
		
		//if siteId is not defined
		if(params['container']['siteId'] == null)
			params['container']['siteId'] = 1;
			

		//create the player
		if(params['player'] != null){
			params['player']['targetDiv'] = playerDiv;
			params['player']['platformId'] = params['container']['platformId'];
			params['player']['propertyId'] = params['container']['propertyId'];
			params['player']['siteId'] = params['container']['siteId'];
			params['player']['environment'] = environment;
			params['player']['urlRedirectPrefix'] = params['container']['urlRedirectPrefix'];
			params['player']['allowOverlays'] = params['player']['windowless'] = params['container']['allowOverlays'];
			params['player']['isSecure'] = (iad.isSecure) ? '1' : '0';
			params['player']['hasCarousel'] = (params['carousel']) ? true : false ;
			new IadPlayerObject(params['player'], false);
		}

		

		//create the channel tool
		if(params['channel'] != null){
			params['channel']['targetDiv'] = channelDiv;
			params['channel']['platformId'] = params['container']['platformId'];
			params['channel']['siteId'] = params['container']['siteId'];
			params['channel']['environment'] = environment;
			params['channel']['allowOverlays'] = params['container']['allowOverlays'];
			params['channel']['isSecure'] = (iad.isSecure) ? '1' : '0';
			new IadChannelObject(params['channel'], false);
		}
		
		

		//create the carousel
		if(params['carousel'] != null){
			params['carousel']['external'] = '0';
			params['carousel']['targetDiv'] = carouselDiv;
			params['carousel']['platformId'] = params['container']['platformId'];
			params['carousel']['propertyId'] = params['container']['propertyId'];
			params['carousel']['siteId'] = params['container']['siteId'];
			params['carousel']['environment'] = environment;
			params['carousel']['urlRedirectPrefix'] = params['container']['urlRedirectPrefix'];
			params['carousel']['allowOverlays'] = params['container']['allowOverlays'];
			params['carousel']['isSecure'] = (iad.isSecure) ? '1' : '0';
			if(params['carousel']['bgColor'] == null || params['carousel']['bgColor'] == undefined)
				params['carousel']['bgColor'] = params['container']['bgColor'];
			new IadCarouselObject(params['carousel'], false);
		}

		
		
		//create the leavebehind
		if(params['leavebehind'] != null){
			params['leavebehind']['allowOverlays'] = params['container']['allowOverlays'];
			if(params['leavebehind']['targetDiv'] == undefined)
				params['leavebehind']['targetDiv'] = lbDiv;
			new IadLeavebehindObject(params['leavebehind'], false);
		}
		
		
		//create the html 
		if(params['html'] != null){
			params['html']['targetDiv'] = htmlDiv;
			new IadHtmlObject(params['html'], false);
		}
		
		//send out widget load success (for js files)
		try{cr4ApiSuccess();}catch(e){}
		
		//set time out to check if all module asset load successfully
		setTimeout(this.widgetTimeout, timeout);
	}, 
	
	
	createExternal: function(params, i)
	{
		
		//check if params are defined
		if(params['container'] == null){
			return;	
		}
		params['container']['allowOverlays'] = '1';

		
		//AFL FANTASY DEMO
		if(this.widgetId == 30 || this.widgetId == 31){
			params['carousel']['style'] = '9';
			params['carousel']['carouselTarget'] = 'lightbox';
		}
		if(randId == undefined)
			randId = Math.ceil(Math.random()*1000);
		//set the target div of the parent side
		var curTargetDiv;
		var curContainerDiv;
		curTargetDiv = document.getElementById(params['container']['targetDiv']);
		targetExtDiv.push(curTargetDiv);
        var extDiv;
		var containerParams = params['container']; 
		if(containerParams != null){
			curContainerDiv = document.createElement("DIV");
			containerExtDiv.push(curContainerDiv);

			setCssStyle(curContainerDiv, 'width', containerParams['width']);
			setCssStyle(curContainerDiv, 'height', containerParams['height']);
			if(containerParams['bgImg'] != null && containerParams['bgImg'] != ''){
				if(containerParams['bgImg'].indexOf("swf") == -1){
					setCssStyle(curContainerDiv, 'backgroundImage', containerParams['bgImg']);
				}
				else{
					var flashDiv = document.createElement("DIV");
					setCssStyle(flashDiv, "position", "absolute");
					setCssStyle(flashDiv, 'width', containerParams['width']);
					setCssStyle(flashDiv, 'height', containerParams['height']);
					curContainerDiv.appendChild(flashDiv);	
					createSwf(flashDiv, containerParams['bgImg'], containerParams['width'], containerParams['height'], '000000', 'containerBg', "", true);
				}
			}
			if(containerParams['bgColor'] != null && containerParams['bgColor'] != '')
				setCssStyle(curContainerDiv, 'backgroundColor', "#"+containerParams['bgColor']);

                        curTargetDiv.appendChild(curContainerDiv);
		}else{
			return;	
		}
		//create external carousel
		if(params['carousel'] != null){
			//CAROUSEL DIV
			var carouselParams = params['carousel'];
			if(carouselParams != null){
				extDiv = document.createElement("DIV");
				setCssStyle(extDiv, "position", "absolute");
				setCssStyle(extDiv, "marginLeft", carouselParams['xPos']);
				setCssStyle(extDiv, "marginTop", carouselParams['yPos']);
				setCssStyle(extDiv, 'width', carouselParams['width']);
				setCssStyle(extDiv, 'height', carouselParams['height']);
				curContainerDiv.appendChild(extDiv);
			}else{
				return;
			}
			//create the carousel
			params['carousel']['external'] = '1';
			params['carousel']['instance'] = i;
			params['carousel']['targetDiv'] = extDiv;
			params['carousel']['platformId'] = params['container']['platformId'];
			params['carousel']['propertyId'] = params['container']['propertyId'];
			params['carousel']['siteId'] = params['container']['siteId'];
			params['carousel']['environment'] = environment;
			params['carousel']['urlRedirectPrefix'] = params['container']['urlRedirectPrefix'];
			params['carousel']['allowOverlays'] = params['container']['allowOverlays'];
			params['carousel']['isSecure'] = (iad.isSecure) ? '1' : '0';
			if(params['carousel']['bgColor'] == null || params['carousel']['bgColor'] == undefined)
				params['carousel']['bgColor'] = params['container']['bgColor'];
			new IadCarouselObject(params['carousel'], false);
		}

		//create external leavebehind
		if(params['leavebehind'] != null){
			iadDebug("leavebehind");
			//leavebehind DIV
			var lbParams = params['leavebehind'];
			if(lbParams != null){
				extDiv = document.createElement("DIV");
				setCssStyle(extDiv, "position", "absolute");
				setCssStyle(extDiv, "marginLeft", lbParams['xPos']);
				setCssStyle(extDiv, "marginTop", lbParams['yPos']);
				setCssStyle(extDiv, 'width', lbParams['width']);
				setCssStyle(extDiv, 'height', lbParams['height']);
				curContainerDiv.appendChild(extDiv);
			}else{
				return;
			}
			
			
			//create the carousel
			params['leavebehind']['external'] = '1';
			params['leavebehind']['targetDiv'] = extDiv;
			params['leavebehind']['pageDiv'] = curTargetDiv;
			params['leavebehind']['allowOverlays'] = params['container']['allowOverlays'];
			new IadLeavebehindObject(params['leavebehind'], false);
		}

	},
	
	
	createDivs: function(params, targetDiv)
	{

		//CONTAINER DIV
		var containerParams = params['container'];
		if(containerParams != null){
			if(containerDiv)
				this.clearWidget();
			
			containerDiv = document.createElement("DIV");
			containerDiv.id = "containerDiv";
			setCssStyle(containerDiv, 'width', containerParams['width']);
			setCssStyle(containerDiv, 'height', containerParams['height']);
			if(containerParams['bgImg'] != null && containerParams['bgImg'] != ''){
				if(containerParams['bgImg'].indexOf("swf") == -1){
					setCssStyle(containerDiv, 'backgroundImage', containerParams['bgImg']);
				}
				else{
					var flashDiv = document.createElement("DIV");
					setCssStyle(flashDiv, "position", "absolute");
					setCssStyle(flashDiv, 'width', containerParams['width']);
					setCssStyle(flashDiv, 'height', containerParams['height']);
					containerDiv.appendChild(flashDiv);	
					createSwf(flashDiv, containerParams['bgImg'], containerParams['width'], containerParams['height'], '000000', 'containerBg', "", true);
				}
			}
			if(containerParams['bgColor'] != null && containerParams['bgColor'] != '')
				setCssStyle(containerDiv, 'backgroundColor', "#"+containerParams['bgColor']);
			
			targetDiv.appendChild(containerDiv);
		}else{
			return;	
		}

		
		//HTML DIV
		var htmlParams = params['html'];
		if(htmlParams != null){
			htmlDiv = document.createElement("DIV");
			htmlDiv.id = "htmlDiv";
			setCssStyle(htmlDiv, "position", "absolute");
			setCssStyle(htmlDiv, "marginLeft", htmlParams['xPos']);
			setCssStyle(htmlDiv, "marginTop", htmlParams['yPos']);
			setCssStyle(htmlDiv, 'width', htmlParams['width']);
			setCssStyle(htmlDiv, 'height', htmlParams['height']);
			containerDiv.appendChild(htmlDiv);	
		}
		
		
		//PLAYER DIV
		var playerParams = params['player'];
		if(playerParams != null){
			playerDiv = document.createElement("DIV");
			playerDiv.id = "playerDiv";
			setCssStyle(playerDiv, "position", "absolute");
			setCssStyle(playerDiv, "marginLeft", playerParams['xPos']);
			setCssStyle(playerDiv, "marginTop", playerParams['yPos']);
			setCssStyle(playerDiv, 'width', playerParams['width']);
			setCssStyle(playerDiv, 'height', getHeight(playerParams, false));
			containerDiv.appendChild(playerDiv);
		}
		
		
		//CHANNEL DIV
		var channelParams = params['channel'];
		if(channelParams != null){
			channelDiv = document.createElement("DIV");
			channelDiv.id = "channelDiv";
			setCssStyle(channelDiv, "position", "absolute");
			setCssStyle(channelDiv, "marginLeft", channelParams['xPos']);
			setCssStyle(channelDiv, "marginTop", channelParams['yPos']);
			setCssStyle(channelDiv, 'width', channelParams['width']);
			setCssStyle(channelDiv, 'height', channelParams['height']);
			containerDiv.appendChild(channelDiv);	
		}
		
		
		//CAROUSEL DIV
		var carouselParams = params['carousel'];
		if(carouselParams != null){
			carouselDiv = document.createElement("DIV");
			carouselDiv.id = "carouselDiv";
			setCssStyle(carouselDiv, "position", "absolute");
			setCssStyle(carouselDiv, "marginLeft", carouselParams['xPos']);
			setCssStyle(carouselDiv, "marginTop", carouselParams['yPos']);
			setCssStyle(carouselDiv, 'width', carouselParams['width']);
			setCssStyle(carouselDiv, 'height', carouselParams['height']);
			containerDiv.appendChild(carouselDiv);
		}
		

		//LEAVBEHIND DIV
		var lbParams = params['leavebehind'];
		if(lbParams != null){
			
			if(params['leavebehind']['targetDiv'] == undefined){
				lbDiv = document.createElement("DIV");
				lbDiv.id = "lbDiv";	
			}else{
				lbDiv = document.getElementById(params['leavebehind']['targetDiv']);
			}

			setCssStyle(lbDiv, "position", "absolute");
			setCssStyle(lbDiv, "marginLeft", lbParams['xPos']);
			setCssStyle(lbDiv, "marginTop", lbParams['yPos']);
			setCssStyle(lbDiv, 'width', lbParams['width']);
			setCssStyle(lbDiv, 'height', lbParams['height']);
			
			if(params['leavebehind']['targetDiv'] == undefined)
				containerDiv.appendChild(lbDiv);	
		}
	},



        checkLightBoxLoaded: function(){
            var result = false;

            if(typeof jQuery !== 'undefined'){
               if(typeof jQuery().colorbox !== 'undefined'){
                    var test = document.createElement("div");
                    test.id = "test";
                    document.body.appendChild(test);
                    $('#test').addClass("_css_loaded_test");
                    if($('#test').css('display') === "none")
                        result = true;
               }
            }


            if(result){
                clearInterval(lightBoxInt);
                this.lightBoxLoaded = true;
            }
        },
	
	
	
	
	widgetTimeout: function(){
		//alert("widgetTimeout "+loadedModuleAssetCount+" / "+totalModuleAssetCount);
		if(loadedModuleAssetCount < totalModuleAssetCount){
			try{cr4AssetTimeout("timeout", "javascript-flash");}catch(e){}
		}
	}, 
	
	
	
	setModuleAssetLoaded: function(module){
		iadDebug("setModuleAssetLoaded "+module);
		if(widgetLoaded)
			return;

		loadedModuleAssetCount++;
		iadDebug("loadedModuleAssetCount "+loadedModuleAssetCount+"/"+totalModuleAssetCount);
		if(loadedModuleAssetCount == totalModuleAssetCount){
			widgetLoaded = true;
			var objFlash = getObject("flashObjCr4");
			if(objFlash){
				if(typeof(objFlash.setAssetLoaded) == 'function')
					objFlash.setAssetLoaded();
			}
		}
	},
	
	
	
	playerInit: function(){
		iadDebug("playerInit");
		if(typeof(initContentObj) =='object'){
			iadCarouselInstance.callCarousel({'asFunction':'playFromCarousel', 'contentId':initContentObj['data']['contentId']});
                        initContentObj = null;
                }
		try{cr4LoadSuccess();}catch(e){}
		
		if(this.widgetId == 12){
			try{console.log('init countdown');}catch(e){}
			var obj = {
				'id' : 'AdArea02', 
				'asFunction' : 'loadLeaveBehind', 
				'url' : 'https://infinity.netventures.tv/Web/Asset/Jive-Dominos-Intro-V6.swf', 
				'adId' : '-1'
			};
			this.callLb(obj);
			try{console.log('init countdown done');}catch(e){}
		}
	},
	
	
	
	//play new content
	cr4PlayContent: function(params){
		
		if(params['autoStart'] == undefined)
			params['autoStart'] = '1';

                if(this.lightBoxLoaded){
			this.cr4InitLightBox({'iadFunction':'cr4PlayContent', 'contentId':params['contentId']});
		}
                else{
                    if(iadPlayerInstance)
			iadPlayerInstance.cr4PlayContent(params);
                }
	},
	
	
	cr4InitCarousel: function(){
        if(this.lightBoxLoaded){
			this.cr4InitLightBox({'iadFunction':'cr4InitCarousel'});
		}
		else{
			if(iadCarouselInstance)
				iadCarouselInstance.callCarousel({'asFunction':'initCarousel'});
				iadCarouselInstance.callCarousel({'asFunction':'initCarousel'});
		}
		
	},


	cr4PlayFromCarousel: function(params){
		if(this.lightBoxLoaded){
			this.cr4InitLightBox({'iadFunction':'cr4PlayFromCarousel', 'contentId':params['contentId']});
		}
                else{
                    if(iadCarouselInstance)
                            iadCarouselInstance.callCarousel({'asFunction':'playFromCarousel', 'contentId':params['contentId']});       
                }
		
	},
	
	

	cr4iVideo: function(params){
		iadPlayerInstance.cr4iVideo(params);  
	},
	
	
	
	cr4Play: function(){
		if(iadPlayerInstance)
			iadPlayerInstance.cr4Play();
	}, 
	cr4Pause: function(){
		if(iadPlayerInstance)
			iadPlayerInstance.cr4Pause();
	}, 
	cr4Stop: function(){
		if(iadPlayerInstance)
			iadPlayerInstance.cr4Stop();
	}, 
	
	
	cr4CallFunction: function(obj){
		if(iadPlayerInstance){
			var cr4Obj = {'status':obj['call']};
			if(obj['callback']) cr4Obj['callback'] = obj['callback'];
			if(obj['value']) cr4Obj['value'] = obj['value'];
			iadPlayerInstance.sendCommand(cr4Obj);
		}	
	},
	
	
	callLb: function(obj){
		if(iadLbInstance[obj['id']]){
			iadLbInstance[obj['id']].callLb(obj);
		}else if(iadLbExtInstance[obj['id']]){
            iadLbExtInstance[obj['id']].callLb(obj);
		}
	},

	setLbVisibility: function(obj){
		if(iadLbInstance){
			if(obj['external'] == '1'){
				iadLbExtInstance[obj['targetArea']].setVisibility(obj['val']);
			}
			else{
				iadLbInstance[obj['targetArea']].setVisibility(obj['val']);
			}
		}
	}, 
	
	
	cr4InitLightBox: function(params){
            if(this.lightBoxLoaded){

                var string = "?iadFunction=" + params['iadFunction'] + "&contentId=" + params['contentId'] + "&widgetId="+this.lightBoxWidgetId;
                if(checkDebug() == 1)
                    string += "&debugNv=1";

                $.colorbox({innerWidth:widgetParams['widget']['container']['width'],
					innerHeight:widgetParams['widget']['container']['height'],
					initialWidth:widgetParams['widget']['container']['width'],
					initialHeight:widgetParams['widget']['container']['height'],
					inline:true,
					iframe:true,
					scrolling:false,
					href: getDomain() + '/App/InfinityPlayer/Html/LightBox/index.php' + string,
                                        onOpen:function()
                                        {
                                                //objMediaPlayer.clearWidget();
                                        },
					onLoad:function()
					{
						//$('#cboxClose').css({display:'none'});
						//objMediaPlayer.handlerOnSuccess();
					},
                                        onCleanup:function()
                                        {
                                                //objMediaPlayer.cr4Stop();
                                        }
				});
            }
	}
};



















/*********************************/
/*

IAD PLAYER

*/
/**********************************/


var IadPlayerObject = function(params, initOnLoad)
{
	//check if params exists
	if(params == null){
		return;
	}else{
		iadPlayerInstance = this;

		this.params = params;		
		
		if(initOnLoad){
			//init player on page loaded
			if(window.addEventListener)
				window.addEventListener("load", iadOnLoad.player, false);
			else if(window.attachEvent) window.attachEvent("onload", iadOnLoad.player);
			else window.onload = iadOnLoad.player;
		}else{
			//init player on user command
			this.init();
		}
	}
};



IadPlayerObject.prototype =
{
	init: function()
	{
        //set the target div
		if(typeof(this.params['targetDiv']) == 'string'){
			this.targetDiv = document.getElementById(this.params['targetDiv']);
		}else{
			this.targetDiv = this.params['targetDiv'];
		}
		
		
		if(randId == undefined)
			randId = Math.ceil(Math.random()*1000);


		
		for(var i in this.params){
			if(this.params[i] == "" || this.params[i] == null)
				delete this.params[i];
		}
		
		
		//check if debug should be on
		this.params['debug'] = checkDebug();


		//check if player invokes content
		this.params['invoke']  = '0';
		var invokeObj = checkInvoke();
		if(invokeObj['doInvoke']){
			delete this.params['url'];
			if(!this.params['hasCarousel']){
				this.params['contentId'] = invokeObj['contentId'];
				this.params['autoStart']  = '1';
				this.params['invoke']  = '1';
			}
		}
		
		//catch domain and url
		if(hostDomain == undefined){
			this.params['domain'] = location.hostname;
			this.params['location'] = encodeURIComponent(location.toString().split("?")[0], "UTF-8");
		}else{
			this.params['domain'] = hostDomain;
			this.params['location'] = hostLocation;
		}
		
		
		//escape target level
		if(this.params['targetLevel']){
			this.params['targetLevel'] = this.params['targetLevel'].toUpperCase();
			if(this.params['targetLevel'].indexOf('&') != -1){
				this.params['targetLevel'] = this.params['targetLevel'].replace("&", "_amp_");
			}
		}




		//fix bgColor if in wrong format
		if(this.params['bgColor']){
			if(this.params['bgColor'].indexOf("#") != -1){
				this.params['bgColor'] = this.params['bgColor'].replace("#", "");
			}
		}
		
		
		//for bigpond site log the omniture environment if exists
		if(this.params['siteId'] == '1')
			if(typeof(s) == 'object')
				if(s.un)
					this.params['omnitureEnv'] = s.un;

		
		
		//create title and unmetered logo if required
		if(this.params['showTitle'] == '1' || this.params['showUnmetered'] == '1')
			this.createTitle();
		

                //if device is iPhone or iPad, use the html5 player
		if(container == 'html5'){
			if(iadHtml5Instance != null)
				iadHtml5Instance.createPlayer(this.params);
				
			return;
		}
			
			
		//create the flash comm asset
		if(flashCom == null)
			iadWidgetInstance.createFlashCom(false);



		//create the url
		var url = getDomain() + "indexInfinityPlayer.php" + this.getParamStr();
		

		
		//create iframe for video holder
		var iFrameWidth = this.params['width'];
		var iFrameHeight = getHeight(this.params, true);
		if(this.params['debug'] == '1' && this.params['wmv'] == '1')
			iFrameWidth = 2*Number(this.params['width']);
		
		
		var iframeDiv = document.createElement("DIV");
		iframeDiv.id = "iframe";
		setCssStyle(iframeDiv, "width", this.params['width']);
		setCssStyle(iframeDiv, "height", iFrameHeight);
		this.targetDiv.appendChild(iframeDiv);

		var date = new Date();
		var iframe=document.createElement("iframe");
                iframe.setAttribute("name","iframe_"+date.getTime());
		iframe.setAttribute("id","iframe_"+date.getTime());
		iframe.setAttribute("src",url);
		iframe.setAttribute("scrolling","no");
		iframe.setAttribute("allowTransparency","true");
		iframe.setAttribute("frameBorder","0");
		
		setCssStyle(iframe, "align", "center");
		setCssStyle(iframe, "margin", 0);
		setCssStyle(iframe, "width", iFrameWidth);
		setCssStyle(iframe, "height", iFrameHeight);
		setCssStyle(iframe, "border", 0);
		iframeDiv.appendChild(iframe);
		

		
		//create title and unmetered logo if required
		if(this.params['showDescription'] == '1')
			this.createDescription();
		


		this.vol = 80;

		this.curTime = 0;
		this.totTime = 0;
		this.dProgress = 0;
	}, 
	
	
	
	createTitle: function(){
		var titleDiv = document.createElement("DIV");
		titleDiv.id = "titleDiv";
		setCssStyle(titleDiv, "width", this.params['width']);
		setCssStyle(titleDiv, "height", this.params['titleHeight']);
		this.targetDiv.appendChild(titleDiv);
		
		var flashVars = "randId="+randId+"&debug="+this.params['debug']+"&cStyle="+this.params['cStyle']+"&fontSize="+this.params['fontSize']+"&fontColor="+this.params['fontColor']+"&titleHeight="+this.params['titleHeight']+"&titleWidth="+this.params['width']+"&showUnmetered="+this.params['showUnmetered']+"&showTitle="+this.params['showTitle'];
		
		var swfUrl = getDomain()+"App/InfinityPlayer/Flash/title.swf?rand="+rand;
		createSwf(titleDiv, swfUrl, this.params['width'], this.params['titleHeight'], '000000', 'flashTitle', flashVars, (this.params['allowOverlays'] == '1'));
	},
	
	
	
	createDescription: function(){
		var descriptionDiv = document.createElement("DIV");
		descriptionDiv.id = "descriptionDiv";
		setCssStyle(descriptionDiv, "width", this.params['width']);
		setCssStyle(descriptionDiv, "height", this.params['descriptionHeight']);
		this.targetDiv.appendChild(descriptionDiv);
		
		var flashVars = "randId="+randId+"&debug="+this.params['debug']+"&cStyle="+this.params['cStyle']+"&fontSize="+this.params['dFontSize']+"&fontColor="+this.params['dFontColor']+"&descriptionHeight="+this.params['descriptionHeight']+"&descriptionWidth="+this.params['width']+"&showDescription="+this.params['showDescription'];
		
		var swfUrl = getDomain()+"App/InfinityPlayer/Flash/description.swf?rand="+rand;
		createSwf(descriptionDiv, swfUrl, this.params['width'], this.params['descriptionHeight'], '000000', 'flashDescription', flashVars, (this.params['allowOverlays'] == '1'));
	},
	
	
	
	//create the param string
	getParamStr: function(){
		//set random id for flash comm
		this.params['randId'] = randId;
		
		//set the os
		this.params['os'] = getOs();
	
		//define it silverlight is supported
		if(this.params['silverlight'] == '1' || !iad.isIE){
			this.params['os'] = 'MacOs';
		}
		
		//check if a formated has been selected - default to wmv
		if((this.params['wmv'] == undefined || this.params['wmv'] == 0) && (this.params['flv'] == undefined || this.params['flv'] == 0)){
			this.params['wmv'] = '1';
			this.params['flv'] = '0';
		}else if(this.params['wmv'] == undefined && this.params['flv'] == 1){
			this.params['wmv'] = '0';
		}
		
		//if no wmv is required set os to windows -> no silverlight created
		if(this.params['wmv'] == '0')
			this.params['os'] = 'Windows';
			
		os = this.params['os'];
		
		//fix bDuration param
		if(this.params['bDuration']){
			if(this.params['bDuration'] == '0' && this.params['wmv'] == '1' && !iad.isIE)
				delete this.params['bDuration'];
		}
		
		
		//set to MacOs 
		if(iad.isGecko && this.params['windowless'] == '1' && this.params['wmv'] == '1'&& this.params['os'] != 'MacOs'){
			os = this.params['os'] = 'MacOs';
		}
		
		
	  
		//don't show tool tip
		if(this.params['os'] != 'MacOs' && (this.params['flv'] == '0' || this.params['flv'] == undefined)){
			//this.params['showTooltip'] = this.params['showMenu'] = '0';
		}
				
		
		
		
		//encode urls
		if(this.params['bClickThrough'] != undefined){
			this.params['bClickThrough'] = encodeURIComponent(this.params['bClickThrough'], "UTF-8");	
		}
		
		delete this.params['xPos'];
		delete this.params['yPos'];
		delete this.params['silverlight'];
		
		var paramStr = "";
		for(var obj in this.params){
			param = this.params[obj];
			if(param != "" && param != null){
				// if it is a url it needs to be encoded
				if(obj == "url"){
					param = escape(param);
				}
				
				if(obj != 'metaData' && obj != 'targetDiv'){
					if(paramStr == ''){
						paramStr = "?" + obj + "=" + param;
					}else{
						paramStr += "&" + obj + "=" + param;
					}	
				}
			}
		}
		
		
		//if is ivideo attach metadata params
		for(obj in this.params){
			if(obj == 'metaData'){
				param = this.params[obj];
				for(var i in param){

					paramStr += "&" + i + "=" + param[i];
				}
			}
		}
	
		return paramStr;
	}, 
	
	
	
	callTitle: function(params){
		var objFlash = getObject("flashTitle");
		if(objFlash){
			if(typeof(objFlash.callTitle) == 'function')
				objFlash.callTitle(params);
		}
	},
	
	
	
	callDescription: function(params){
		var objFlash = getObject("flashDescription");
		if(objFlash){
			if(typeof(objFlash.callDescription) == 'function')
				objFlash.callDescription(params);
		}
	},
	
	
	
	callFlashCom: function(func, params){
		var objFlash = getObject("flashObjCr4");
		if(objFlash){
			if(typeof(objFlash[func]) == 'function')
				objFlash[func](params);
		}
	},
	
	
	
	//play new content
	cr4PlayContent: function(params){
		
		if(params['targetLevel'])
			params['targetLevel'] = params['targetLevel'].toUpperCase();
			
		if(params['bDuration']){
			if(params['bDuration'] == '0' && !iad.isIE)
				delete params['bDuration'];
		}
			
		params['holdingImgDefault'] = '0';
		if(container != "html5"){
			this.callFlashCom("playContent", params);
		}
		else{
			if(iadHtml5Instance)
				iadHtml5Instance.cr4PlayContent(params);
		}
		
		
		this.curTime = 0;
		this.totTime = 0;
		this.dProgress = 0;
	},
	
	
	//play new content
	cr4iVideo: function(params){
		this.callFlashCom("cr4iVideo", params);  
	},
	
	
	
	//commands send from external control on client side
	sendCommand: function(params){
		this.callFlashCom("sendCommand", params);
		
		if(params['status'] == 'volume')
			this.vol = params['value'];
	},
	
	
	
	playCompletedApi: function(status, url){
		if(status == 'Content'){
			try{cr4ContentCompleted(url);}catch(e){}
		}
	
		if(status == 'Ad'){
			try{cr4AdCompleted(url);}catch(e){}
		}
	
		if(status == 'All'){
			this.curTime = 0;
			this.totTime = 0;
		}
	}, 
	


	playStartedApi: function(status){
		if(status == 'Content'){
			try{cr4ContentStarted();}catch(e){}
		}
	
		if(status == 'Ad'){
			try{cr4AdStarted();}catch(e){}
		}
	},	

	setError: function(error){
		try{cr4ErrorOccured(error);}catch(e){}
	},
	
	getDownloadProgressReturn: function(value){
		try{cr4GetDownloadProgressReturn(value);}catch(e){}
	}, 
	
	cr4CheckTime: function(){
		this.sendCommand({'status':'time'});
	},
	
	cr4GetCurTime: function(){
		return this.curTime;
	},
	
	cr4GetDuration: function(){
		return this.totTime;
	},
	
	cr4GetDownloadProgress: function(){
		return this.dProgress;
	}, 
	
	cr4GetVolume: function(){
		return this.vol;
	},
	
	cr4GetOs: function(){
		return os;
	},
	
	cr4Play: function(){
		this.sendCommand({'status':'play'});
	},
	
	cr4Pause: function(){
		this.sendCommand({'status':'pause'});
	},
	
	cr4Stop: function(){
		this.sendCommand({'status':'stop'});
		this.curTime = 0;
		this.totTime = 0;
	},
	
	cr4FastForward: function(){
		this.sendCommand({'status':'fastForward'});
	},
	
	cr4FastReverse: function (){
		this.sendCommand({'status':'fastReverse'});
	},
	
	cr4SetVolume: function(value){
		this.sendCommand({'status':'volume', 'value':Number(value)});
	},
	
	cr4SetCurrentPos: function(value){
		this.sendCommand({'status':'setCurrentPos', 'value':Number(value)});
	},
	
	cr4FullScreen: function(){
		this.sendCommand({'status':'fullScreen'});
	}, 
	
	cr4SendToFriend: function(){
		this.sendCommand({'status':'stf'});
	}
};



















/*********************************/
/*

IAD CHANNEL TOOL

*/
/**********************************/

var IadChannelObject = function(params, initOnLoad)
{
	//check if params exists
	if(params == null){
		return;
	}else{
		iadChannelInstance = this;
		this.params = params;
		
		if(initOnLoad){
			//init player on page loaded
			if(window.addEventListener)
				window.addEventListener("load", iadOnLoad.channel, false);
			else if(window.attachEvent) window.attachEvent("onload", iadOnLoad.channel);
			else window.onload = iadOnLoad.channel;
		}else{
			//init player on user command
			this.init();
		}
	}
};



IadChannelObject.prototype =
{

	init: function()
	{
		var parentDiv;
		
		if(typeof(this.params['targetDiv']) == 'string'){
			parentDiv = document.getElementById(this.params['targetDiv']);
			
			//create div for channel swf
			var channelDiv = document.createElement("DIV");
			channelDiv.id = "channelDiv";
			channelDiv.style.width = this.params['width'];
			channelDiv.style.height = this.params['height'];
			channelDiv.style.margin = 0;
			channelDiv.style.padding = 0;
			parentDiv.appendChild(channelDiv);
		}else{
			channelDiv = this.params['targetDiv'];
		}
		
		
		
		for(var i in this.params){
			if(this.params[i] == "" || this.params[i] == null)
				delete this.params[i];
		}
		
		
		this.params['debug'] = checkDebug();
		
		
		//set the environment for loading the nav
		this.params['domain'] = getDomain();

		
		//define the chosen style swf
		if(this.params['style'] != undefined){
			var swfUrl = getDomain()+"App/InfinityPlayer/Flash/channel_iad_"+this.params['style']+".swf?rand="+rand;
		}else{
			alert('Please specify a style');
			return;	
		}
		
		
		if(this.params['bg'] != undefined){
			try {this.params['bg'] = iad.decode(this.params['bg']);} catch(e){alert(e);delete this.params['bg']}
			
			if(this.params['bg']){
				for(i in this.params['bg']){
					this.params["bg_" + i] = this.params['bg'][i];
				}
			}
		}
		
		
		//SET DEFAULT target level
		if(this.params['targetLevel'] == undefined){
			this.params['targetLevel'] = 'VIDEOS';
		}
		
		
		//if more than one activeColor is defined, replace the seperator
		if(this.params['activeColor'].indexOf(",") != 1){
			this.params['activeColor'] = this.params['activeColor'].split(",").join("_sep_");
		}
		

		
		//create the swf and add to dom
		var flashVars = 'randFlashId='+randId;
		for(i in this.params){
			if(this.params[i] != "" && this.params[i] != null)
				flashVars += '&'+ i + '=' + this.params[i];	
		}
		createSwf(channelDiv, swfUrl, this.params['width'], this.params['height'], '000000', 'flashChannel', flashVars, (this.params['allowOverlays'] == '1'));

	}
};



















/*********************************/
/*

IAD CAROUSEL

*/
/**********************************/



var IadCarouselObject = function(params, initOnLoad)
{
	//check if params exists
	if(params == null){
		return;
	}else{
                if(params['external'] == '1'){
			iadCarouselExtInstance = this;
			this.instance = 'iadCarouselExtInstance_'+params['instance'];
		}else{
			iadCarouselInstance = this;
			this.instance = 'iadCarouselInstance';
			//this.instance = 'iadCarouselInstance_'+randId;
		}
		this.params = params;

		if(initOnLoad){
			//init player on page loaded
			if(window.addEventListener)
				window.addEventListener("load", iadOnLoad.carousel, false);
			else if(window.attachEvent) window.attachEvent("onload", iadOnLoad.carousel);
			else window.onload = iadOnLoad.carousel;
		}else{
			//init player on user command
			this.init();
		}
	}
};



IadCarouselObject.prototype =
{
	init: function()
	{
		//alert('init carousel');
		
		var parentDiv;
		
		if(typeof(this.params['targetDiv']) == 'string'){
			parentDiv = document.getElementById(this.params['targetDiv']);
			
			//create div for carousel swf
			var carouselDiv = document.createElement("DIV");
			carouselDiv.id = "carouselDiv";
			setCssStyle(carouselDiv, "width", this.params['width']);
			setCssStyle(carouselDiv, "height", this.params['height']);
			setCssStyle(carouselDiv, "margin", 0);
			setCssStyle(carouselDiv, "padding", 0);
			parentDiv.appendChild(carouselDiv);
		}else{
			carouselDiv = this.params['targetDiv'];
		}
		
		
		//this.params['playlistUser'] = '1';
		this.params['expandClip'] = '1';
		
		for(var i in this.params){
			if(this.params[i] == "" || this.params[i] == null)
				delete this.params[i];
		}
		
		
		this.xPos = this.params['xPos'];
		
		
		//temp
		if(this.params['paginationStyle'] == undefined)
			this.params['paginationStyle'] = '1';
		//temp
		
		
		if(this.params['playlistUser'] == '0')
			delete this.params['playlistUser'];
			
			
		//adjust clip width/height for style 2
		if(this.params['style'] == '2'){
			if(this.params['expandClip'] == '1'){
				this.params['clipWidth'] = Number(this.params['imageWidth']) + 2;
				this.params['clipHeight'] = Number(this.params['imageHeight']) + 2;	
			}
			
			if(this.params['playlistUser'] == '1')
				this.params['clipHeight'] = Number(this.params['clipHeight']) + 9;
		}
	
		
		//if playlistUser is set to true, create a tab param
		if(this.params['playlistUser'] == '1' && this.params['tabs'] == undefined){
			var title = (this.params['title'] != undefined) ? this.params['title'] : "";
			delete this.params['title'];
			this.params['tabs'] = '[{"tabTitle":"'+title+'","tabTargetLevel":"'+this.params['targetLevel']+'","tabTarget":"widget","tabContentSearch":{"searchBy":"","startDate":"","endDate":""}}]';	
		}
		
		
		//define the chosen style swf
		if(this.params['style'] != undefined){
			var swfUrl = getDomain()+"App/InfinityPlayer/Flash/carousel_iad_"+this.params['style']+".swf?rand="+rand;
		}else{
			alert('Please specify a style');
			return;	
		}
		
		
		//validate target level
		if(this.params['targetLevel'] != undefined){
			this.params['targetLevel'] = this.params['targetLevel'].toUpperCase();
			if(this.params['targetLevel'].indexOf('&') != -1){
				this.params['targetLevel'] = this.params['targetLevel'].replace("&", "_amp_");
			}
		}
		//encode urls to be passed as flash vars
		if(this.params['linkUrl'] != undefined){
			this.params['linkUrl'] = encodeURIComponent(this.params['linkUrl'], "UTF-8");	
		}
		
		var tabString = "";
		this.contentSearchArray = new Array();

		if(this.params['tabs']){
			try {this.params['tabs'] = eval(this.params['tabs']);} catch(e){alert(e);this.params['tabs']=[]}

			if(this.params['tabs'].length != 0){
				var tabTitleStr = "";
				var tabTargetLevelStr = "";
				var tabLiveChannelIdsStr = "";
				var tabTargetStr = "";
				var tabContentSearchStr = "";
				
				for(i=0; i<this.params['tabs'].length; i++){
					tabTitleStr += "_sep_"+this.params['tabs'][i]['tabTitle'];
					tabTargetLevelStr += "_sep_"+this.params['tabs'][i]['tabTargetLevel'];
					tabLiveChannelIdsStr += (this.params['tabs'][i]['tabLiveChannelIds'] != undefined) ? "_sep_"+this.params['tabs'][i]['tabLiveChannelIds'] : "_sep_";
					tabTargetStr += "_sep_"+this.params['tabs'][i]['tabTarget'];
					
					var tabContentSearchObj = {};
					if(this.params['tabs'][i]['tabContentSearch']['searchBy'] != "" || this.params['tabs'][i]['tabContentSearch']['startDate'] != "" || this.params['tabs'][i]['tabContentSearch']['endDate'] != ""){
						tabContentSearchStr += "_sep_1";
						for(var j in this.params['tabs'][i]['tabContentSearch']){
							tabContentSearchObj[j] = this.params['tabs'][i]['tabContentSearch'][j];
						}
					}else{
						tabContentSearchStr += "_sep_0";
					}
					this.contentSearchArray[i] = tabContentSearchObj;
				}
				
				//add a playlist tab
				if(this.params['playlistUser'] == '1'){
					tabTitleStr += "_sep_My Playlist";
					tabTargetLevelStr += "_sep_PLAYLIST";
					tabTargetStr += "_sep_widget";
					
					tabContentSearchStr += "_sep_0";
				}
				
				tabString = "&" + "tabTitle=" + tabTitleStr.substring(5) + "&" + "tabTargetLevel=" + tabTargetLevelStr.substring(5) + "&" + "tabLiveChannelIds=" + tabLiveChannelIdsStr.substring(5) + "&" + "tabTarget=" + tabTargetStr.substring(5) + "&" +"tabContentSearch=" + tabContentSearchStr.substring(5);
				
				if(this.params['title'])
					delete this.params['title'];
			}else{
				delete this.params['tabs'];
			}
		}
		

		if(this.params['contentSearch']){
			try {this.params['contentSearch'] = iad.decode(this.params['contentSearch']);} catch(e){delete this.params['contentSearch']}
			if(this.params['contentSearch']){
				this.contentSearchArray[0] = this.params['contentSearch'];	
				this.params['contentSearch'] = '1';
			}
		}
		
		
		//check if debug is on
		this.params['debug'] = checkDebug();
		
		this.params['carouselInstance'] = this.instance;
		
		//check if player invokes content -> set autoStart to false
		var invokeObj = checkInvoke();
		if(invokeObj['doInvoke']){
			this.params['autoStart']  = '0';
			this.params['contentId'] = invokeObj['contentId'];
			this.params['invoke']  = '1';
		}			
			
		//delete unnecessary params
		delete this.params['targetDiv'];
		delete this.params['xPos'];
		delete this.params['yPos'];


        //if device is iPhone or iPad, use the html5 player
		if(container == 'html5'){
			if(iadHtml5Instance != null){
                                iadHtml5Instance.createCarousel(this.params);
                                //carousel.getClipList();
                        }
	
			return;
		}

		
		//create the swf and add to dom
		var flashVars = 'randFlashId='+randId;
		for(i in this.params){
			if(this.params[i] != "" && this.params[i] != null)
				flashVars += '&'+ i + '=' + this.params[i];	
		}
		flashVars += tabString;

		createSwf(carouselDiv, swfUrl, this.params['width'], this.params['height'], '000000', this.instance, flashVars, (this.params['allowOverlays'] == '1'));
	},  
	
	
	serverTimeout: function(){
		try{cr4AssetTimeout("timeout", "carousel");}catch(e){}
	},
	
	
	getContentSearchArray: function(id){
		return 	this.contentSearchArray[id];
	}, 
	
	
	callCarousel: function(obj){
		var objFlash = getObject(this.instance);
		if(objFlash){
			if(typeof(objFlash.callCarousel) == 'function'){
                objFlash.callCarousel(obj);
			}
		}
	}
};

	
	

















/*********************************/
/*

IAD LEAVEBEHIND

*/
/**********************************/

var IadLeavebehindObject = function(params, initOnLoad)
{
	//check if params exists
	if(params == null){
		return;
	}else{
		//temp fix
		if(params['targetArea'] == "AdAreaSml") params['targetArea'] = "AdArea01";
		if(params['targetArea'] == "AdAreaLrg") params['targetArea'] = "AdArea02";
		//temp fix end

        this.instance = params['targetArea'];
		if(params['external'] == '1'){
			iadLbExtInstance[this.instance] = this;
		}else{
			iadLbInstance[this.instance] = this;
		}
		this.targetArea = params['targetArea'];
		
		//iadLbInstance = this;
		this.params = params;
		
		if(initOnLoad){
			//init player on page loaded
			if(window.addEventListener)
				window.addEventListener("load", iadOnLoad.lb, false);
			else if(window.attachEvent) window.attachEvent("onload", iadOnLoad.lb);
			else window.onload = iadOnLoad.lb;
		}else{
			//init player on user command
			this.init();
		}
	}
};



IadLeavebehindObject.prototype =
{
	init: function()
	{
		if(typeof(this.params['targetDiv']) == 'string'){
			this.parentDiv = document.getElementById(this.params['targetDiv']);

			this.lbDiv = document.createElement("DIV");
			this.lbDiv.id = "lbDiv";
			setCssStyle(this.lbDiv, "width", this.params['width']);
			setCssStyle(this.lbDiv, "height", this.params['height']);
			setCssStyle(this.lbDiv, "marginLeft", this.params['xPos']);
			setCssStyle(this.lbDiv, "marginTop", this.params['yPos']);
			this.parentDiv.appendChild(this.lbDiv);
		}else{
			this.lbDiv = this.params['targetDiv'];
		}
		
		if(this.params['targetArea'] == 'AdArea03'){
			setCssStyle(this.parentDiv, "position", "absolute");
			setCssStyle(this.parentDiv, "display", "block");
			setCssStyle(this.parentDiv, "zIndex", "1000");
			setCssStyle(this.parentDiv, "width", this.params['width']);
			setCssStyle(this.parentDiv, "height", this.params['height']);
		}
		
		var swfUrl = getDomain()+"App/InfinityPlayer/Flash/leaveBehindHolder.swf?rand="+rand;
		
		
		this.params['debug'] = checkDebug();
		
		this.params['lbInstance'] = this.instance;
		
		for(var i in this.params){
			if(this.params[i] == "" || this.params[i] == null)
				delete this.params[i];
		}
		
		
		if(this.params['bg'] != undefined){
			try {this.params['bg'] = iad.decode(this.params['bg']);} catch(e){alert(e);delete this.params['bg']}
			
			if(this.params['bg']){
				for(i in this.params['bg']){
					this.params["bg_" + i] = this.params['bg'][i];
				}
			}
		}
		
		var flashVars = 'randFlashId='+randId;
		for(i in this.params){
			flashVars += '&'+ i + '=' + this.params[i];	
		}
		
		createSwf(this.lbDiv, swfUrl, this.params['width'], this.params['height'], '000000', this.instance, flashVars, (this.params['allowOverlays'] == '1'));
	},

	setVisibility: function(val){
		if(this.params['external'] == '1'){
			setVisibility(this.params['pageDiv'], val);
		}
		else{
			setVisibility(this.lbDiv, val);
		}
	}, 
	
	callLb: function(obj){
		var objFlash = getObject(this.instance);
		if(objFlash){
			if(typeof(objFlash.callLb) == 'function')
				objFlash.callLb(obj);
		}
	}
};



















/*********************************/
/*

IAD HTML AREA

*/
/**********************************/

var IadHtmlObject = function(params, initOnLoad)
{
	//check if params exists
	if(params == null){
		return;
	}else{
		iadHtmlInstance = this;
		this.params = params;
		
		if(initOnLoad){
			//init player on page loaded
			if(window.addEventListener)
				window.addEventListener("load", iadOnLoad.html, false);
			else if(window.attachEvent) window.attachEvent("onload", iadOnLoad.html);
			else window.onload = iadOnLoad.html;
		}else{
			//init player on user command
			this.init();
		}
	}
};



IadHtmlObject.prototype =
{
	init: function()
	{
		var parentDiv;
		
		if(typeof(this.params['targetDiv']) == 'string'){
			parentDiv = document.getElementById(this.params['targetDiv']);
			
			//cerate div for swf listener on client side
			var htmlDiv = document.createElement("DIV");
			htmlDiv.id = "htmlDiv";
			htmlDiv.style.width = this.params['width'];
			htmlDiv.style.height = this.params['height'];
			parentDiv.appendChild(htmlDiv);
		}else{
			htmlDiv = this.params['targetDiv'];
		}
		
		if(this.params['type'] == "html"){
			htmlDiv.innerHTML = this.params['value'];
		}else if (this.params['type'] == "image"){
			var img = document.createElement("IMG");
			img.src = this.params['value'];
			htmlDiv.appendChild(img);
		}else{
			htmlDiv.innerHTML = "no type is defined";
		}
	}
};


	
	
	
























//***************** GENERAL COMPONENT CREATION HELPER *******************//


function checkDomain(domainArray){
	var val	 = false;
	
	Array.prototype.inArray=function(oObject){
		for(var i in this){
			if(oObject.indexOf(this[i]) != -1)
				return true;
		}
		return false;
	};
	
	val = domainArray.inArray(location.hostname);
	
	if(!val)
		val = (location.hostname.indexOf("bigpondvideo.com") != -1) ? true : false;
	
	if(location.hostname == 'iad')
		val = true;
	
	return val;
}


//get domain for iad version required
function getDomain(){
	var domain = null;
	
	if(location.hostname == 'vms'){
		domain = getProtocol() + 'iad/';
	}else if(location.hostname == 'vms-demo.iad.tv'){
		domain = getProtocol() + 'demo.iad.tv/';
	}else if(location.hostname == 'vms-testing.netventures.com.au'){
		domain = getProtocol() + 'testing.netventures.com.au/';
	}else if(location.hostname == 'vms-testing01.netventures.com.au'){
		domain = getProtocol() + 'testing01.netventures.com.au/';
	}else if(location.hostname == 'vms-sit.bigpondvideo.com'){
		domain = getProtocol() + 'sit.bigpondvideo.com/';
	}else if(location.hostname == 'vms-staging.iad.netventures.com.au'){
		domain = getProtocol() + 'staging.bigpondvideo.com/';
	}else if(location.hostname == 'vms.bigpondguide.info'){
		domain = getProtocol() + 'embed.bigpondvideo.com/';
	}else if(location.hostname == 'vms.netventures.tv/'){
		domain = getProtocol() + 'infinity.netventures.tv/';
	}else if(location.hostname == 'vms-testing.netventures.tv'){
		domain = getProtocol() + 'infinity-testing.netventures.tv/';
	}
	
	if(domain != null)
		return 	domain;
	
	switch(environment){
		case "local":
			domain = getProtocol() + 'iad/';
			break;
		case "testing":
			domain = getProtocol() + 'testing.netventures.com.au/';
			break;
		case "testing01":
			domain = getProtocol() + 'testing01.iad.netventures.com.au/';
			break;
		case "demoIAd":
			domain = getProtocol() + 'demo.iad.tv/';
			break;
		case "sit":
			domain = getProtocol() + 'sit.bigpondvideo.com/';
			break;
		case "staging":
			domain = getProtocol() + 'staging.bigpondvideo.com/';
			break;
		case "embed":
			domain = getProtocol() + 'embed.bigpondvideo.com/';
			break;
		case "getstreamd-testing":
			domain = getProtocol() + 'iad-testing.getstreamd.netventures.com.au/';
			break;
		case "getstreamd":
			domain = getProtocol() + 'player.getstreamd.com/';
			break;
		case "bigpondvideo":
			domain = getProtocol() + 'bigpondvideo.com/';
			break;
        case "testingUS":
			domain = getProtocol() + 'infinity-testing.netventures.tv/';
			break;
        case "demoUS":
			domain = getProtocol() + 'infinity-demo.netventures.tv/';
			break;
		case "production":
		case "productionAU":
		case "productionUS":
			domain = getProtocol() + 'infinity.netventures.tv/';
			break;
		default:
			if(environment != undefined){
				domain = getProtocol() +environment+'.bigpondvideo.com/';
			}else{
				domain = getProtocol() + 'bigpondvideo.com/';
			}
	}	
	return 	domain;
}

function getProtocol(){
    return (!iad.isSecure) ? "http://" : "https://";
}

//check if debug is needed
function checkDebug(){
	
	var debug = 0;
	var searchUrl = location.search;
	if(searchUrl != ""){
		searchUrl = searchUrl.slice(1);
		param_ar = searchUrl.split("&");
		for(i=0; i<param_ar.length; i++){
			param = param_ar[i].split("=");
			if(param[0] == 'debugNv' && param[1] == '1'){
				debug = 1;
			}
		}	
	}	
	
	return debug;
}


//check if debug is needed
function checkEnvironment(){
	
	var urlEnvironment = "";
	var searchUrl = location.search;
	if(searchUrl != ""){
		searchUrl = searchUrl.slice(1);
		param_ar = searchUrl.split("&");
		for(i=0; i<param_ar.length; i++){
			param = param_ar[i].split("=");
			if(param[0] == 'environment'){
				urlEnvironment = param[1];
			}
		}	
	}	
	
	return urlEnvironment;
}

//check if debug is needed
function checkWidgetId(){
	
	var urlWidgetId = -1;
	var searchUrl = location.search;
	if(searchUrl != ""){
		searchUrl = searchUrl.slice(1);
		param_ar = searchUrl.split("&");
		for(i=0; i<param_ar.length; i++){
			param = param_ar[i].split("=");
			if(param[0] == 'widgetId'){
				urlWidgetId = param[1];
			}
		}	
	}	
	
	return urlWidgetId;
}

//check if container is html5
function checkContainer(){

	var isHtml5 = false;
	var searchUrl = location.search;
	if(searchUrl != ""){
		searchUrl = searchUrl.slice(1);
		param_ar = searchUrl.split("&");
		for(i=0; i<param_ar.length; i++){
			param = param_ar[i].split("=");
			if(param[0] == 'container' && param[1] == 'html5'){
				isHtml5 = true;
			}
		}
	}

	return isHtml5;
}

//check if debug is needed
function checkInvoke(){
	
	var invokeObj = {};
	invokeObj['doInvoke'] = false;
	
	var searchUrl = location.search;
	if(searchUrl != ""){
		searchUrl = searchUrl.slice(1);
		param_ar = searchUrl.split("&");
		for(i=0; i<param_ar.length; i++){
			param = param_ar[i].split("=");
			if(param[0] == 'nvId'){
				invokeObj['doInvoke'] = true;
				invokeObj['contentId'] = param[1];
			}
		}	
	}	
	
	return invokeObj;
}

//get the height of iframe based on settings
function getHeight(params, iframe){
	var playerHeight = 0;

	//check if control bar is needed and what size
	var controlHeight = 0;
	if(params['controls'] == 'internal')
		controlHeight = 25;
	
	playerHeight = Number(params['height']) + controlHeight;
	
	if(!iframe && (params['showUnmetered'] == '1' || params['showTitle'] == '1'))
		playerHeight += Number(params['titleHeight']);
	
	return playerHeight;
}

//get the os
function getOs(){
	var OSName="Unknown OS";
	
	if (iad.isWindows) OSName="Windows";
	if (iad.isMac) OSName="MacOs";
	if (iad.isAir) OSName="Air";
	if (iad.isLinux) OSName="Linux";	
	
	return OSName;
}



//***************** END GENERAL COMPONENT CREATION HELPER *******************//



















/*********************************/
/*

IVIDEO PLAYER 

*/
/**********************************/

var IVideoObject = iad.extend(IadWidgetObject, {

	getMatch: function(iYear, iSeason, iRound, iTeam)
	{
		var params = {'year':iYear, 'season':iSeason, 'round':iRound, 'team':iTeam, quarter:0};
		params['searchMethod'] = 'getMatch';
		//alert(Object.toQueryString(params));
		this.cr4iVideo(params);
	},
	
	getQuarter: function(iYear, iSeason, iRound, iQuarter, iTeam)
	{
		var params = {'year':iYear, 'season':iSeason, 'round':iRound, 'team':iTeam, 'quarter':iQuarter};
		params['searchMethod'] = 'getQuarter';
		this.cr4iVideo(params);
	},
	
	getActivityByPlayer: function(iTeam, iPlayer, iActivity, iMaxVideos, iSortOrder)
	{
		var params = {'team':iTeam, 'player':iPlayer, 'activityType':iActivity, 'maxVideos':iMaxVideos, 'sortOrder':iSortOrder};
		params['searchMethod'] = 'getActivityByPlayer';
		this.cr4iVideo(params);
	},
	
	getActivityByTeam: function(iTeam, iActivity, iMaxVideos, iSortOrder)
	{
		var params = {'team':iTeam, 'activityType':iActivity, 'maxVideos':iMaxVideos, 'sortOrder':iSortOrder};
		params['searchMethod'] = 'getActivityByTeam';
		this.cr4iVideo(params);
	},
	
	getActivityBySeason: function(iYear, iSeason, iActivity, iMaxVideos, iSortOrder)
	{
		var params = {'year':iYear, 'season':iSeason, 'activityType':iActivity, 'maxVideos':iMaxVideos, 'sortOrder':iSortOrder};
		params['searchMethod'] = 'getActivityBySeason';
		this.cr4iVideo(params);
	},
	
	getActivityByRound: function(iYear, iSeason, iRound, iActivity, iMaxVideos, iSortOrder)
	{
		var params = {'year':iYear, 'season':iSeason, 'round':iRound, 'activityType':iActivity, 'maxVideos':iMaxVideos, 'sortOrder':iSortOrder};
		params['searchMethod'] = 'getActivityByRound';
		this.cr4iVideo(params);
	},
	
	getPlayerBySeason: function(iYear, iSeason, iTeam, iPlayer, iActivity, iMaxVideos, iSortOrder)
	{
		var params = {'year':iYear, 'season':iSeason, 'team':iTeam,  'player':iPlayer, 'activityType':iActivity, 'maxVideos':iMaxVideos, 'sortOrder':iSortOrder};
		params['searchMethod'] = 'getPlayerBySeason';
		this.cr4iVideo(params);
	},
	
	getPlayerByRound: function(iYear, iSeason, iRound, iTeam, iPlayer, iActivity, iMaxVideos, iSortOrder)
	{
		var params = {'year':iYear, 'season':iSeason, 'round':iRound, 'team':iTeam, 'player':iPlayer, 'activityType':iActivity, 'maxVideos':iMaxVideos, 'sortOrder':iSortOrder};
		params['searchMethod'] = 'getPlayerByRound';
		this.cr4iVideo(params);
	},
	
	getTeamBySeason: function(iYear, iSeason, iTeam, iActivity, iMaxVideos, iSortOrder)
	{
		var params = {'year':iYear, 'season':iSeason, 'team':iTeam, 'activityType':iActivity, 'maxVideos':iMaxVideos, 'sortOrder':iSortOrder};
		params['searchMethod'] = 'getTeamBySeason';
		this.cr4iVideo(params);
	},
	
	getTeamByRound: function(iYear, iSeason, iRound, iTeam, iActivity, iMaxVideos, iSortOrder)
	{
		var params = {'year':iYear, 'season':iSeason, 'round':iRound, 'team':iTeam, 'activityType':iActivity, 'maxVideos':iMaxVideos, 'sortOrder':iSortOrder};
		params['searchMethod'] = 'getTeamByRound';
		this.cr4iVideo(params);
	},
	
	getMatchData: function(iYear, iSeason, iRound, iTeam, iPlayer, iActivity, iActivityPosition, iMaxVideos, iSortOrder)
	{
		var params = {'year':iYear, 'season':iSeason, 'round':iRound, 'team':iTeam, 'player':iPlayer, 'activityType':iActivity, 'activityPosition':iActivityPosition, 'maxVideos':iMaxVideos, 'sortOrder':iSortOrder};
		params['searchMethod'] = 'getMatchData';
		this.cr4iVideo(params);
	},
	
	getMatchDataByScore: function(iYear, iSeason, iRound, iTeam, iTeamAScore, iTeamBScore)
	{
		var params = {'year':iYear, 'season':iSeason, 'round':iRound, 'team':iTeam, 'teamAScore':iTeamAScore, 'teamBScore':iTeamBScore};
		params['searchMethod'] = 'getMatchDataByScore';
		this.cr4iVideo(params);
	}
});



//***************** END IVIDEO CALLS ****************//



















//***************** MISCELEANEOUS ****************//

//check if flash is installed
function FlashInstalled(){
    result = false;
    
    if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]){
        result = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
    }
    else if (document.all && (navigator.appVersion.indexOf("Mac")==-1)){
        eval ('try {var xObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if (xObj) result = true; xObj = null; } catch (e) {}');
    }
    return result;
}
//set css style for divs
function setCssStyle(target, property, value){
	switch(property){
		case 'width':
		case 'height':
		case 'left':
		case 'top':
		case 'marginLeft':
		case 'marginTop':
			if(iad.isIE && !iad.isIE9)
				target.style[property] = value;
			else
				target.style[property] = value+"px";
			break;
			
		case 'backgroundImage':
			target.style.backgroundImage = "url("+value+")";
			break;
		
		default:
			target.style[property] = value;
	}
}
//cerate swfs
function createSwf(div, url, width, height, bgcolor, id, flashVars, transparentFlash){
	
	//if(iad.isIE || iad.isChrome){		//removed Nov 9th 2010 because players didn't load in Chrome
	if(iad.isIE){
		var flash = '';
		flash += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + getProtocol() + 'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" ';
		flash += 'WIDTH='+width+' HEIGHT='+height+' id='+id+'>';
		flash += '<PARAM NAME=movie VALUE='+url+'>';
		flash += '<PARAM NAME=quality VALUE=high>';
		flash += '<PARAM NAME=bgcolor VALUE=#000000>';
		flash += '<PARAM NAME=AllowScriptAccess VALUE="always">';
		flash += '<PARAM NAME=flashvars VALUE="'+flashVars+'">';
		if(transparentFlash)
			flash += '<PARAM NAME=wmode VALUE="transparent">';
		flash += '<EMBED href='+url+' quality=high bgcolor=#000000 WIDTH='+width+' HEIGHT='+height+' NAME='+id+' AllowScriptAccess="always" ';
		if(transparentFlash)
			flash += 'wmode="transparent" ';
		flash += 'TYPE="application/x-shockwave-flash" PLUGINSPAGE="' + getProtocol() + 'www.macromedia.com/go/getflashplayer" flashvars='+flashVars+'></EMBED></OBJECT>';
		div.innerHTML = flash;
		
	}else{
		var em=document.createElement("object");
		em.setAttribute("classid","clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
		em.setAttribute("codebase","' + getProtocol() + 'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0");
		em.setAttribute("width",width);
		em.setAttribute("height",height);
		em.setAttribute("movie",url);
		em.setAttribute("flashVars",flashVars);
		em.setAttribute("allowScriptAccess","always");
		if(iad.isIE){
			em.id=id;	
			em.setAttribute("name",id);
		}
		if(transparentFlash)
			em.setAttribute("wmode","transparent");
                if(bgcolor != "")
                        em.setAttribute("bgcolor",("#"+bgcolor));
		
		var pr3=document.createElement("param");
		pr3.setAttribute("name","allowScriptAccess");
		pr3.setAttribute("value","always");
		em.appendChild(pr3);
		if(!window.ActiveXObject){
			var embed=document.createElement("embed");
			embed.setAttribute("src",url);
			embed.setAttribute("id",id);
			embed.setAttribute("name",id);
			embed.setAttribute("qality","high");
			embed.setAttribute("width",width);
			embed.setAttribute("height",height);
			embed.setAttribute("allowScriptAccess","always");
			embed.setAttribute("flashVars",flashVars);
			if(transparentFlash)
				embed.setAttribute("wmode","transparent");
                        if(bgcolor != "")
                            embed.setAttribute("bgcolor",("#"+bgcolor));
			embed.setAttribute("type","application/x-shockwave-flash");
			em.appendChild(embed);
		}
		
		div.appendChild(em);
	}
	
	return document.getElementById(id);
}
//get the flash object
function getObject(movieName) {
	var obj;
	obj = document.getElementById(movieName);
	if(obj == undefined){
		if (iad.isIE) {
			obj = window[movieName];
		}else {			
			obj = document[movieName];
		}	
	}
	return obj;
}
//set visibility of various divs (mainly flashOver)
function setVisibility(div, status){
	if(typeof(div) == 'string')
		div = document.getElementById(div);
	
	if(iad.isIE){
		if(status){
			div.style.margin = 0;
		}else{
			div.style.margin = -2000;
		}
	}else{
		if(status){
			div.style.margin = "0px";
		}else{
			div.style.margin = "-2000px";
		}
	}
}
//click through from leave behind
function clickThrough(url, target, depth, width, height, acl){

	var newWindow = false;
	if(url == 'null' || url == null	){
		return newWindow;
	}
	
	leftVal = (screen.width - width) / 2;
	topVal = (screen.height - height) / 2;
	if(acl == '1'){
		tools = "location=yes,scrollbars=yes,resizable=yes,width="+width+",height="+height+",left="+leftVal+",top="+topVal;
	}else{
		tools = "location=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+",left="+leftVal+",top="+topVal;
	}
	
	if(target == "Same"){
		//open location in same window
		location.href=url;
		return true;
	}else{
		if(window.open(url, 'newWin', tools)){
			return true;
		}else{
			return false;
		}
	}
}
//prints out parameters of object beinmg passsed back to user
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	 
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	 
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			   
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
	  	dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}
function clone(obj){
    if(obj == null || typeof(obj) != 'object')
        return obj;

    var temp = obj.constructor(); // changed

    for(var key in obj)
        temp[key] = clone(obj[key]);
    return temp;
}
function addJavascript(uri, pos) {
    var th = document.getElementsByTagName(pos)[0];
    var s = document.createElement('script');
    s.setAttribute('type', 'text/javascript');
    s.setAttribute('src', uri);
    th.appendChild(s);
}
function addCss(uri, pos){
    var th = document.getElementsByTagName(pos)[0];
    var css = document.createElement("link");
    css.setAttribute("href",uri);
    css.setAttribute("media","screen");
    css.setAttribute("rel","stylesheet");
    css.setAttribute("type","text/css");
    th.appendChild(css);
}

function isCSSLoaded(uri) {
    var links = document.getElementsByTagName("link");
    for (var i =0, len = links.length; i<len;++i) {
        if (links[i].getAttribute("src") === uri) return true;
    }
    return false;
}







function iadDebug(str){
    try{debug(str);}catch(e){}
}
