var requiredMajorVersion = 8;
var requiredMinorVersion = 0;
var requiredRevision = 0;
var jsVersion = 1.0;

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
if (isOpera) {requiredMajorVersion = 9;}
jsVersion = 1.1;
function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
  // NS/Opera version >= 3 check for Flash plugin in plugin array
        if (navigator.plugins != null && navigator.plugins.length > 0) {
                if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
                        var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
                var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
                        descArray = flashDescription.split(" ");
                        tempArrayMajor = descArray[2].split(".");
                        versionMajor = tempArrayMajor[0];
                        versionMinor = tempArrayMajor[1];
                        if ( descArray[3] != "" ) {
                                tempArrayMinor = descArray[3].split("r");
                        } else {
                                tempArrayMinor = descArray[4].split("r");
                        }
                versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
        } else {
                        flashVer = -1;
                }
        }
        // MSN/WebTV 2.6 supports Flash 4
        else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
        // WebTV 2.5 supports Flash 3
        else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
        // older WebTV supports Flash 2
        else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
        // Can't detect in all other cases
        else {

                flashVer = -1;
        }
        return flashVer;
}
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
        reqVer = parseFloat(reqMajorVer + "." + reqRevision);
        for (i=25;i>0;i--) {
                if (isIE && isWin && !isOpera) {
                        versionStr = ControlVersion();
                } else {
                        versionStr = JSGetSwfVer(i);
                }
                if (versionStr == -1 ) {
                        return false;
                } else if (versionStr != 0) {
                        if(isIE && isWin && !isOpera) {
                                tempArray         = versionStr.split(" ");
                                tempString        = tempArray[1];
                                versionArray      = tempString .split(",");
                        } else {
                                versionArray      = versionStr.split(".");
                        }
                        versionMajor      = versionArray[0];
                        versionMinor      = versionArray[1];
                        versionRevision   = versionArray[2];

                        versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
                        versionNum        = parseFloat(versionString);
                        if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
                                return true;
                        } else {
                                return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
                        }
                }
        }
        return (reqVer ? false : 0.0);
}

var google_ad_client = '_120x600';
var google_ad_width = 120;
var google_ad_height = 600;
var google_ad_format = '120x600_pas_abgc';
var google_safe = 'high';
var google_color_bg = 'F9F9F9';
var google_color_border = 'CC0000';

function LFCScroller(){return true;}

function switch_section(sec,sub){
    i = 0;
    do
    {
        var current_section = null;
        if ( document.all){
            current_section = document.all['section_'+sec+'_'+i];}
        else if ( document.getElementById ){
            current_section = document.getElementById('section_'+sec+'_'+i);}
        if ( current_section != null ){ 
            current_section.style.overflow = ( i == sub ? 'visible' : 'hidden' );
            current_section.style.visibility = ( i == sub ? 'visible' : 'hidden' );
        }
        i++;
    } while ( current_section != null );
}

function setLFCHomepage(obj, page)
{
    if ( parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")+5)) >= 5 )
    {
        obj.style.behavior='url(#default#homepage)';
        obj.setHomePage(page);        
    }
}

function addLFCPlayer(no,name,pos, url)
{
    document.writeln('<tr class=feature>');
    document.writeln('<td width=23 height=16 bgcolor=#cccccc align=center>'+no+'</td>');
    document.writeln('<td width=179><a href="'+url+'">'+name+'</a></td>');
    document.writeln('<td width=29>'+pos+'</td>');
    document.writeln('</tr>');
}

hasFlash = false;
hasFlash = DetectFlashVer(8,0,0);

function LFCAdServer(w,h)
{
    this.width = w;
    this.height = h;
    this.prefix = "";
    this.external = "";
    this.weight = 0;
    this.monitor = null;
    this.size = 0;
    this.date = new Date();
    this.ads = new Array();
    this.adchannels = new Array();
    this.paddyads = new Array();
    this.channels = new Array(
	'news',
	'shop',
	'match',
	'interactive',
	'mobile',
	'tickets',
	'team',
	'history',
	'club'
    );
    for (i=0;i<this.channels.length;i++)
    {
    	this.adchannels[this.channels[i]] = new Array();
    }
    this.add = function(img,url,alt,weight,start,end,channel,type) {

	        this.showme = true;

		//rep, replacement displayed only if no flash
		if ( (type=='gif' && hasFlash==true) || (hasFlash==false && type=='swf'))
		{
			this.showme = false;
		}
		else 
		{
			if ( start != '' )
			{
				start = new Date(start);
				if ( start > this.date )
				{
					this.showme = false;
				}
			}
			if ( end != '' )
			{
				end = new Date(end);
				if ( end < this.date )
				{
					this.showme = false;
				}
			}
		}
		if ( this.showme )
		{
			this.ads[this.size] = new Array();
			if (channel != null)
			{
				for (y=weight;y>=0;y--)
				{
					if (channel == 'all')
					{
					    for (i=0;i<this.channels.length;i++)
					    {
						this.adchannels[this.channels[i]][this.adchannels[this.channels[i]].length] = this.size;
					    }
					}
					else this.adchannels[channel][this.adchannels[channel].length] = this.size;

				}
				this.ads[this.size]["img"] = 'http://www.liverpoolfc.servecast.com/downloads/liverpoolfc/mpu_ads/' + img;
			}
			else
			{
				for (y=weight;y>0;y--)
				{
					this.paddyads[this.paddyads.length] = this.size;
				}
				this.ads[this.size]["img"] = this.prefix + img;
			}
			this.ads[this.size]["url"] = url;
			this.ads[this.size]["alt"] = alt;
			this.ads[this.size]["weight"] = weight;
			this.ads[this.size]["channel"] = channel;

			this.extension = img.substring(img.lastIndexOf(".")).toUpperCase();

			if (this.external == ' target="_blank"' || this.extension == ".GIF" || this.extension == ".JPG" || this.extension == ".JPEG")
			{
				this.ads[this.size]["tag"] = '<img src="'+this.ads[this.size]["img"]+'" alt="'+this.ads[this.size]["alt"]+'" width="'+this.width+'" height="'+this.height+'" border="0" />';
			}
			else if ( this.extension == ".SWF" )
			{
				this.ads[this.size]["tag"] = '<object width="'+this.width+'" height="'+this.height+'"><param name="movie" value="'+this.ads[this.size]["img"]+'"><embed src="'+this.ads[this.size]["img"]+'" width="'+this.width+'" height="'+this.height+'"></embed></object>';
			}
			else
			{
				this.size--;
			}
			this.size++;
		}

    }
    this.setInternal = function() {
        this.prefix = '/ads/';
    }
    this.setExternal = function() {
        this.external = ' target="_blank"';
    }
	this.display = function(channel) {
		if (channel != null)
		{
			//channel is for mpu ads not on homepage
			adref = Math.floor(Math.random() * this.adchannels[channel].length);
			ad = this.adchannels[channel][adref];
		}
		else 
		{
			adref = Math.floor(Math.random() * this.paddyads.length);
			ad = this.paddyads[adref];
		}
		if (this.ads[ad]["url"] != '') document.write('<a href="'+this.ads[ad]["url"]+'"'+this.external+'>');
		document.write(this.ads[ad]["tag"]);
		if (this.ads[ad]["url"] != '') document.write('</a>');
	}
}

var AdGroup = Math.round(Math.random() * 100000000);
function ExternalAdServer() {
  this.server = 'http://adserver.adtech.de/';
  this.standard = new Array();
  this.standard[0] = 'addyn|3.0|512|';
  this.standard[1] = 'ADTECH;loc=100;target=_blank;sub1=[subst];key=key1+key2+key3+key4;grp=';
  this.standard[2] = ';misc=';

  this.id = new Array();
  this.id["home"] = new Array();
  this.id["home"]["banner"] = '1010169|0|1|';
  this.id["home"]["richmedia"] = '1019648|0|16|';
  this.id["news"] = new Array();
  this.id["news"]["banner"] = '1019652|0|1|';
  this.id["news"]["extra"] = '1019652|0|1|';
  this.id["news"]["skyscraper"] = '1019651|0|168|';
  this.id["news"]["richmedia"] = '1019653|0|16|';
  this.id["match"] = new Array();
  this.id["match"]["banner"] = '1019655|0|1|';
  this.id["match"]["skyscraper"] = '1019654|0|168|';
  this.id["match"]["richmedia"] = '1019656|0|16|';
  this.id["shop"] = new Array();
  this.id["shop"]["banner"] = '1019657|0|1|';
  this.id["shop"]["skyscraper"] = '1019659|0|168|';
  this.id["shop"]["richmedia"] = '1019658|0|16|';
  this.id["interact"] = new Array();
  this.id["interact"]["banner"] = '1019664|0|1|';
  this.id["interact"]["skyscraper"] = '1019665|0|168|';
  this.id["interact"]["richmedia"] = '1019663|0|16|';
  this.id["mobile"] = new Array();
  this.id["mobile"]["banner"] = '1019666|0|1|';
  this.id["mobile"]["skyscraper"] = '1019667|0|168|';
  this.id["mobile"]["richmedia"] = '1019668|0|16|';
  this.id["tickets"] = new Array();
  this.id["tickets"]["banner"] = '1019669|0|1|';
  this.id["tickets"]["skyscraper"] = '1019671|0|168|';
  this.id["tickets"]["richmedia"] = '1019670|0|16|';
  this.id["team"] = new Array();
  this.id["team"]["banner"] = '1019673|0|1|';
  this.id["team"]["skyscraper"] = '1019674|0|168|';
  this.id["team"]["richmedia"] = '1019672|0|16|';
  this.id["history"] = new Array();
  this.id["history"]["banner"] = '1019676|0|1|';
  this.id["history"]["skyscraper"] = '1019675|0|168|';
  this.id["history"]["richmedia"] = '1019677|0|16|';
  this.id["club"] = new Array();
  this.id["club"]["banner"] = '1019680|0|1|';
  this.id["club"]["skyscraper"] = '1019679|0|168|';
  this.id["club"]["richmedia"] = '1019678|0|16|';
  this.id["ros"] = new Array();
  this.id["ros"]["banner"] = '1010171|0|1|';

  this.display = function(section, type) {

    var html = "";
	if (section == '' && type == '')
	{
		html = "<img src=\"http://www.liverpoolfc.tv/ads/m0407_liverpool-5star_145x145.gif\" />"
		document.write(html);
	}

    // If ad hits are not acceptable remove the following two lines
    if ( type == "extra" )
     	  return;
    // If ad hits are acceptable remove the following four lines
    //if ( type == "extra" ) {
    //   html = '<br/>&nbsp;<br/>';
    //   document.write(html); 
    //}
	  
    html = '<scr'+'ipt language="JavaScript1.1" src="'+this.server+this.standard[0]+this.id[section][type]+this.standard[1]+AdGroup+this.standard[2]+new Date().getTime()+'"></scr'+'ipt>';
    document.write(html);
    if ( type == "banner" && section != "ros" ) {
        html = '<scr'+'ipt language="JavaScript1.1" src="'+this.server+this.standard[0]+this.id[section]["richmedia"]+this.standard[1]+AdGroup+this.standard[2]+new Date().getTime()+'"></scri'+'pt>';
        document.write(html);
    }
  }

}

var PaddyPowerAds = new LFCAdServer(300,145);
var LFCAds145x145 = new LFCAdServer(300,250);

LFCAds145x145.setInternal();
PaddyPowerAds.setInternal();

// PaddyPowerAds.add("ppgeneric.gif","http://www.paddypower.com/bet?action=cmp&cid=37&AFF_ID=321","FREE 10 POUND BET",1,"01 MARCH     2007 00:03","03 DECEMBER  2007 04:03");
// PaddyPowerAds.add("ppgeneric.gif","http://www.paddypower.com/bet?action=cmp&cid=37&AFF_ID=321","FREE 10 POUND BET",1,"25 APRIL     2007 19:45","25 APRIL     2010 19:45");
PaddyPowerAds.add("generic.jpg","http://www.paddypowerpoker.com/index.php?AFF_ID=320","LFC Official Online Poker from Paddy Power",1,"25 APRIL     2007 19:45","25 APRIL     2010 19:45");
PaddyPowerAds.add("windaprem.gif","http://www.paddypower.com/bet?action=go_type&category=SPECIALS&disp_cat_id=&ev_class_id=169&ev_type_id=8398&ev_oc_grp_ids=48214&bir_index=&cid=37&AFF_ID=321","wintheleague",5,"19 JUNE      2007 11:00","22 JUNE      2007 18:00");
PaddyPowerAds.add("LFC BB.gif","http://www.paddypower.com/bet?action=go_type&category=SPECIALS&ev_class_id=104&ev_type_id=8293&promo=news_SecondComing&crea=lnk&cid=37&AFF_ID=321","bb",1,"01 JUNE      2007 14:15","31 JULY      2007 12:00");
//PaddyPowerAds.add("<!--IMG-->","<!--URL-->","<!--ALT-->",<!--WEIGHT-->,<!--START-->,<!--END-->);


//LFCAds145x145.add("<!--IMG-->","<!--URL-->","<!--ALT-->","<!--weight-->","<!--start-->","<!--end-->","<!--channel-->","<!--type-->");


var ExternalAds = new ExternalAdServer();
function homeban(){ ExternalAds.display("home", "banner"); }
function newsban(){ ExternalAds.display("news", "banner"); }
function news145(){ LFCAds145x145.display('news'); }
function newsgad(){ ExternalAds.display("news", "skyscraper"); }
function featgad(){ ExternalAds.display("news", "skyscraper"); }
function shopban(){ ExternalAds.display("shop", "banner"); }
function shop145(){ LFCAds145x145.display('shop'); }
function shopgad(){ ExternalAds.display("shop", "skyscraper"); }
function matcban(){ ExternalAds.display("match", "banner"); }
function matc145(){ LFCAds145x145.display('match'); }
function matcgad(){ ExternalAds.display("match", "skyscraper"); }
function inteban(){ ExternalAds.display("interact", "banner"); }
function inte145(){ LFCAds145x145.display('interactive'); }
function integad(){ ExternalAds.display("interact", "skyscraper"); }
function mobiban(){ ExternalAds.display("mobile", "banner"); }
function mobi145(){ LFCAds145x145.display('mobile'); }
function mobigad(){ ExternalAds.display("interact", "skyscraper"); }
function tickban(){ ExternalAds.display("tickets", "banner"); }
function tick145(){ LFCAds145x145.display('tickets'); }
function tickgad(){ ExternalAds.display("tickets", "skyscraper"); }
function teamban(){ ExternalAds.display("team", "banner"); }
function team145(){ LFCAds145x145.display('team'); }
function teamgad(){ ExternalAds.display("team", "skyscraper"); }
function histban(){ ExternalAds.display("history", "banner"); }
function hist145(){ LFCAds145x145.display('history'); }
function histgad(){ ExternalAds.display("history", "skyscraper"); }
function clubban(){ ExternalAds.display("club", "banner"); }
function club145(){ LFCAds145x145.display('club'); }
function clubgad(){ ExternalAds.display("club", "skyscraper"); }

function home145(){ LFCAds145x145.display(''); }
function homegad(){ ExternalAds.display("home", "skyscraper"); }
