//PANEL functions
var spacerImage='/images/spacer.gif';

function setState(tabNum) {if (tabNum==cd[1]) {$("#tab"+tabNum).css("background","url(" + staticSite + "/images/tabs/tab" + tabNum + "-ON.gif) no-repeat");}else {$("#tab"+tabNum).css("background","url(" + staticSite + "/images/tabs/tab" + tabNum + ".gif) no-repeat");}}
function hidePanel() {$("#tab"+cd[1]).css("background","url(" + staticSite + "/images/tabs/tab" + cd[1] + ".gif) no-repeat");}
function hover(tabNum) {$("#tab"+tabNum).css("background","url(" + staticSite + "/images/tabs/tab" + tabNum + "-ON.gif) no-repeat");}
function panelPicOver(id) {$("#" + id).css("border","1px solid #b68b3f");}
function panelPicOut(id) {$("#" + id).css("border","1px solid #606464");}
function setText(id,text){$("#" + id).html(text);}
function setImage(id,src,text){$("#" + id).attr("src",staticSite + "/" + src);$("#" + id).attr("alt",text);}
function getCurItem(){return getItem(cd[1],cd[2][cd[1]]);}
function getItem(x,y){return items[x][y];}
function showFirstPanel(id){showPanel(id);}
function moveLeft(){if((cd[3][cd[1]])>1){cd[3][cd[1]]-=4;updateThumbnails(cd[3][cd[1]]);updateCounterText();}}
function moveRight(){if(((cd[3][cd[1]])+4)<items[cd[1]].length){cd[3][cd[1]]+=4;updateThumbnails(cd[3][cd[1]]);updateCounterText();}}
function imgClick(item){showItem((cd[3][cd[1]])+item-1);}


function initSchedule()
{
	// this initialises the demo scollpanes on the page.
	$('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 17});
	$('#pane2').jScrollPane({showArrows:false, scrollbarWidth: 15, arrowSize: 16});
	$('#pane3').jScrollPane();
}

//current displayed
var cd = new Array();
cd[1]=1;
cd[2]=new Array();
cd[2][1]=1;
cd[2][2]=1;
cd[2][3]=1;
cd[3]=new Array();
cd[3][1]=1;
cd[3][2]=1;
cd[3][3]=1;

// create all the arrays
var items=new Array();
items[1]=new Array();
items[2]=new Array();
items[3]=new Array();

var headings=new Array();
headings[1]=['NOW READING //','FULL ARTICLE','RELATED CONTENT //'];
headings[2]=['NOW PLAYING //','PLAY MULTIMEDIA','RELATED CONTENT //'];
headings[3]=['NOW SHOWING //','VIEW PHOTO GALLERY','RELATED CONTENT //'];

function addItem(type, count,title,date,desc,link,related1Title,related1Url,related1Target,related2Title,related2Url,related2Target,related3Title,related3Url,related3Target,image)
{
var temp=new Object();
temp.title=title;
temp.date=date;
temp.desc=desc;
temp.link=link;
temp.relatedTitle=new Array();
temp.relatedTitle[1]=related1Title;
temp.relatedTitle[2]=related2Title;
temp.relatedTitle[3]=related3Title;
temp.relatedUrl=new Array()
temp.relatedUrl[1]=related1Url;
temp.relatedUrl[2]=related2Url;
temp.relatedUrl[3]=related3Url;
temp.relatedTaget=new Array()
temp.relatedTaget[1]=related1Target;
temp.relatedTaget[2]=related2Target;
temp.relatedTaget[3]=related3Target;
temp.image=image;
items[type][count]=temp;
}

function showPanel(panelid)
{
// check and see if we are currently playing a video
if(videoPlaying){stopFlv();}
if(mp3Playing){stopMP3(null);}
showSplash();

// set the current panel
hidePanel();
// update the current panel
cd[1]=panelid;
// turn off old tab image
setState(cd[1]);
// change any text we need
setText("heading",headings[panelid][0]);
setText("link1",headings[panelid][1]);
setText("heading2",headings[panelid][2]);
// update the images at the bottom
var s=cd[3][panelid];
updateThumbnails(s);
// update the text at the bottom
updateCounterText();
// show the current item
showItem(cd[2][cd[1]]);
// turn on or off the photo gallery ad
if(panelid==3){$("#pgAd").css("display","inline");}else{$("#pgAd").css("display","none");}
}

function updateCounterText()
{
var max=(cd[3][cd[1]]+3);
if(max>((items[cd[1]].length)-1)){max=((items[cd[1]].length)-1);}
setText("counter",cd[3][cd[1]] + '-' + max + ' of ' + ((items[cd[1]].length)-1) );
}

function updateThumbnails(s)
{
var is="?w=82&mw=82&h=46&mh=46&bc=492f0c";
var max=(items[cd[1]].length-1);
if(max>=(s+0)){setImage("imgThumb1",(getItem(cd[1],s+0).image + is),(getItem(cd[1],s+0).title));}else{setImage("imgThumb1",spacerImage,'');}
if(max>=(s+1)){setImage("imgThumb2",(getItem(cd[1],s+1).image + is),(getItem(cd[1],s+1).title));}else{setImage("imgThumb2",spacerImage,'');}
if(max>=(s+2)){setImage("imgThumb3",(getItem(cd[1],s+2).image + is),(getItem(cd[1],s+2).title));}else{setImage("imgThumb3",spacerImage,'');}
if(max>=(s+3)){setImage("imgThumb4",(getItem(cd[1],s+3).image + is),(getItem(cd[1],s+3).title));}else{setImage("imgThumb4",spacerImage,'');}
}

function showItem(itemId)
{
var i=getItem(cd[1],itemId);
if(i!=null)
{
// update the text
setText("headline",i.title);
setText("datetime",i.date);
setText("text",i.desc);
setText("rel1",i.relatedTitle[1]);
setText("rel2",i.relatedTitle[2]);
setText("rel3",i.relatedTitle[3]);

// update the image
setImage("imgMain",i.image + "?w=480&mw=480&h=270&mh=270&bc=000000",i.title);

// update the current selected item
cd[2][cd[1]]=itemId;

}
}


function RelatedClick(item)
{
var temp=getCurItem().relatedUrl[item];
window.location=temp;
//alert(temp);
}

function fullClick()
{
// check out what we are on, and go from there
switch(cd[1])
{
case 1:  // news
    window.location=getCurItem().link;
    break;
case 3: // photogallery
    lpg(getCurItem().link,getCurItem().title);
    break;
case 2: // multimedia
    // first check and see if we are playing anything
    if(videoPlaying){stopFlv();}
    if(mp3Playing){stopMP3(null);}
    if(realPlaying){stopReal();}

    var media=getCurItem().link;
    // look at the ext to figure out what to do
    if(media.toLowerCase().lastIndexOf("flv")==media.length-3)
    {playFlv(media);}
    if(media.toLowerCase().lastIndexOf("mp3")==media.length-3)
    {playMP3(media);}
    if(media.toLowerCase().lastIndexOf("rm")==media.length-2)
    {playReal(media);}
    break;
}
}
