// rotating photos script by Vlad Mettler // version 1.2 // contact: info@pixeldesign.pl //initialise data array var data=new Array(); //initialise array holding number of currently displayed photo (for each set of photos) var arrCurrent=new Array(); //initialise array holding info on state of set (prev=-1, pause=0 or next=+1) var arrCurrentState=new Array(); //initialise array that holds references for timeouts for different boxes var arrTimeout=new Array(); function rotateForward(intWhichSet){ stopPhoto(intWhichSet); if (eval('document.images["prev'+intWhichSet+'"]')){ eval('document.images["prev'+intWhichSet+'"].src=prev.src') eval('document.images["pause'+intWhichSet+'"].src=pause.src') eval('document.images["next'+intWhichSet+'"].src=next_on.src') } arrCurrentState[intWhichSet]=1; changePhoto(intWhichSet); } function rotateStop(intWhichSet){ if (eval('document.images["prev'+intWhichSet+'"]')){ eval('document.images["prev'+intWhichSet+'"].src=prev.src') eval('document.images["pause'+intWhichSet+'"].src=pause_on.src') eval('document.images["next'+intWhichSet+'"].src=next.src') } arrCurrentState[intWhichSet]=0; stopPhoto(intWhichSet); } function rotateBackwards(intWhichSet){ stopPhoto(intWhichSet); if (eval('document.images["prev'+intWhichSet+'"]')){ eval('document.images["prev'+intWhichSet+'"].src=prev_on.src') eval('document.images["pause'+intWhichSet+'"].src=pause.src') eval('document.images["next'+intWhichSet+'"].src=next.src') } arrCurrentState[intWhichSet]=-1; changePhoto(intWhichSet); } function pressedButton(intWhichSet, strWhichButton){ eval('document.images["'+strWhichButton+intWhichSet+'"].src='+strWhichButton+'_over.src') } function Photo(imgSrc,articleId,caption) { imgSrc=new String(imgSrc); imgSrc=imgSrc.slice(imgSrc.indexOf(">")+1); this.img=new Image(); this.img.src=imgSrc; this.url="http://cgi.wn.com/?t=worldnews/onephoto.txt&action=display&article="+articleId; // cut the string to fit the box this.caption=caption; if (this.caption.length>60){ this.caption=this.caption.slice(0,60); if (this.caption.charAt(this.caption.length-1)!=' '){ this.caption=this.caption.slice(0, this.caption.lastIndexOf(' '))+"..."; } } } Photo.prototype.set=function(intWhichSet) { eval("dest"+intWhichSet+"=this.url;"); //alert("a"); if (!document.all){ //NS+Moz+Opera+PocketIE if(navigator.userAgent.indexOf('Windows CE')!=-1){ //Pocket IE eval('document.images["photo'+intWhichSet+'"].src=this.img.src'); if (obj=new Object(eval('div_textlink'+intWhichSet))){ obj.innerHTML=''+this.caption+''; } } else { eval('document.images["photo'+intWhichSet+'"].src=this.img.src'); //NS+Moz+Opera if (eval("document.links['textlink"+intWhichSet+"']")){ eval("document.links['textlink"+intWhichSet+"'].href=this.url"); eval("document.links['textlink"+intWhichSet+"'].target='_blank'"); eval("document.links['textlink"+intWhichSet+"'].innerHTML=this.caption"); } } } else { //IE eval('document.images["photo'+intWhichSet+'"].src=this.img.src'); if (objHTML=new Object(eval('document.all.div_textlink'+intWhichSet))){ objHTML.innerHTML=''+this.caption+''; } } } var dest=""; function redirect(intWhichSet) { eval("window.open(dest"+intWhichSet+")"); } function changePhoto(intWhichSet) { if (arrCurrentState[intWhichSet]!=0){ current=(arrCurrent[intWhichSet]+arrCurrentState[intWhichSet])%data[intWhichSet].length; if (current==-1){ current=data[intWhichSet].length-1; } arrCurrent[intWhichSet]=current; data[intWhichSet][current].set(intWhichSet); arrTimeout[intWhichSet]=setTimeout("changePhoto("+eval(intWhichSet)+")",5000); } } function stopPhoto(intWhichSet){ clearTimeout(arrTimeout[intWhichSet]); } function fetchFromURL(arg){ if (location.href.indexOf("?")!=-1){ args=location.href.substring(location.href.indexOf("?")+1, location.href.length) arrArgs=args.split("&"); //for (x=0; x0) { arrCurrent[intWhichSet]=0; arrCurrentState[intWhichSet]=1; data[intWhichSet][0].set(intWhichSet); rotateForward(intWhichSet); } else { data[intWhichSet][0]=new Photo("http://cgi.wn.com/shared/active_photos/rotating_default.gif",0,"WN Network"); data[intWhichSet][0].url="http://www.wn.com"; data[intWhichSet][0].set(intWhichSet); } } } function initialiseBox(intWhichSet, boolControls, boolFoot, scheme, boolText, boxWidth, imgWidth, imgHeight, bgColour, bgImage, textSize, textColour, textFont, ctrlBGColour, ctrlBGImage, ctrlButtonWidth, ctrlButtonHeight, ctrlLogoWidth, ctrlLogoHeight, borderWidth) { //some variables can be parsed from the URL // decide which colour scheme is going to be displayed urlScheme=fetchFromURL("scheme"); if (urlScheme!="notdefined"){ scheme=urlScheme; } //override controls setting urlBoolControls=fetchFromURL("boolControls") if (urlBoolControls=='notdefined'){ if (typeof(boolControls)!='boolean'){ (typeof(boolControls)!='boolean')?boolControls=true:false; } } else { if (urlBoolControls=="true"){ boolControls=true; } else { boolControls=false; } } //override logo setting urlBoolFoot=fetchFromURL("boolFoot"); if (urlBoolFoot=='notdefined'){ if (typeof(boolFoot)!='boolean'){ (typeof(boolFoot)!='boolean')?boolFoot=true:false; } } else { if (urlBoolFoot=="true"){ boolFoot=true; } else { boolFoot=false; } } if (boxWidth==undefined){boxWidth=parseInt(fetchFromURL("boxWidth"))} if (imgWidth==undefined){imgWidth=parseInt(fetchFromURL("imgWidth"))} if (imgHeight==undefined){imgHeight=parseInt(fetchFromURL("imgHeight"))} if (borderWidth==undefined){borderWidth=parseInt(fetchFromURL("borderWidth"))} //alert("boxWidth="+boxWidth); //alert("imgWidth="+imgWidth); //alert("imgHeight="+imgHeight); //alert("borderWidth="+borderWidth); //initialise control rollovers prev=new Image(); prev.src="http://cgi.wn.com/shared/active_photos/"+scheme+"/back.gif"; prev_on=new Image(); prev_on.src="http://cgi.wn.com/shared/active_photos/"+scheme+"/back_on.gif"; prev_over=new Image(); prev_over.src="http://cgi.wn.com/shared/active_photos/"+scheme+"/back_over.gif"; pause=new Image(); pause.src="http://cgi.wn.com/shared/active_photos/"+scheme+"/pause.gif"; pause_on=new Image(); pause_on.src="http://cgi.wn.com/shared/active_photos/"+scheme+"/pause_on.gif"; pause_over=new Image(); pause_over.src="http://cgi.wn.com/shared/active_photos/"+scheme+"/pause_over.gif"; next=new Image(); next.src="http://cgi.wn.com/shared/active_photos/"+scheme+"/play.gif"; next_on=new Image(); next_on.src="http://cgi.wn.com/shared/active_photos/"+scheme+"/play_on.gif"; next_over=new Image(); next_over.src="http://cgi.wn.com/shared/active_photos/"+scheme+"/play_over.gif"; wnlink=new Image(); wnlink.src="http://cgi.wn.com/shared/active_photos/"+scheme+"/wn_logo.gif"; wnlink_on=new Image(); wnlink_on.src="http://cgi.wn.com/shared/active_photos/"+scheme+"/wn_logo_on.gif"; //force detfaults (isNaN(boxWidth))?boxWidth=160:true; (isNaN(imgWidth))?imgWidth=150:true; (isNaN(imgHeight))?imgHeight=100:true; (isNaN(borderWidth))?borderWidth=1:true; if (bgColour==null){ if (scheme=="classic"){ bgColour="#fefefe"; } else { bgColour='#dfdfdf' } } (textSize==null)?textSize=12:true; (textColour==null)?textColour='black':true; (textFont==null)?textFont='Arial, Helvetica, sans-serif':true; (typeof(boolFoot)!='boolean')?boolFoot=true:false; (typeof(boolText)!='boolean')?boolText=true:false; (typeof(bgImage)!='boolean')?bgImage=true:false; (ctrlButtonWidth==null)?ctrlButtonWidth=21:true; (ctrlButtonHeight==null)?ctrlButtonHeight=18:true; (ctrlLogoWidth==null)?ctrlLogoWidth=71:true; (ctrlLogoHeight==null)?ctrlLogoHeight=30:true; if (ctrlBGColour==null){ if (scheme=="classic"){ ctrlBGColour="ccddff"; } else { ctrlBGColour='#dfdfdf' } } (typeof(ctrlBGImage)!='boolean')?ctrlBGImage=true:false; ctrlButtonSeparation=3; ctrlMarginTop=5; ctrlMarginBottom=5; // determine additional variables //upper box if (bgImage){ imgBGImage='background-image : url(http://cgi.wn.com/shared/active_photos/'+scheme+'/bgr_top.gif);' } else { imgBGImage=''; } // image imgMarginHorizontal=(boxWidth-imgWidth)/2; ((imgMarginVertical=imgMarginHorizontal)>5)?imgMarginVertical=5:false; //text if (boolText){ textHeight=4*parseInt(textSize); textMarginHorizontal=imgMarginHorizontal; textMarginVertical=3; } else { textHeight=0; textMarginHorizontal=0; textMarginVertical=0; } //controls if (boolControls || boolFoot){ if(ctrlBGImage){ ctrlBGImage='background-image : url(http://cgi.wn.com/shared/active_photos/'+scheme+'/bgr_bottom.gif);'; } if (boolFoot){ ctrlMarginLeft=((boxWidth-ctrlLogoWidth-6)-(3*ctrlButtonWidth)-(2*ctrlButtonSeparation))/2; ctrlHeight=ctrlLogoHeight+ctrlMarginTop+ctrlMarginBottom; ctrlMarginButtonTop=((ctrlHeight-ctrlButtonHeight)+(ctrlMarginTop-ctrlMarginBottom))/2; //ctrlMarginButtonTop=ctrlMarginTop-2; ctrlMarginButtonBottom=ctrlHeight-ctrlButtonHeight-ctrlMarginButtonTop; //ctrlMarginButtonBottom=6; } else { ctrlMarginLeft=(boxWidth-(3*ctrlButtonWidth)-(2*ctrlButtonSeparation))/2; ctrlHeight=ctrlButtonHeight+ctrlMarginTop+ctrlMarginBottom; ctrlMarginButtonTop=((ctrlHeight-ctrlButtonHeight)+(ctrlMarginTop-ctrlMarginBottom))/2; //ctrlMarginButtonTop=ctrlMarginTop-2; ctrlMarginButtonBottom=ctrlHeight-ctrlButtonHeight-ctrlMarginButtonTop; //ctrlMarginButtonBottom=6; } }else{ ctrlHeight=0; } //recalculate the box height boxHeight=imgHeight+(imgMarginVertical*2)+textHeight+ctrlHeight; document.write(''); document.write('
'); document.write('
'); document.write(''); divstyle='style="height:'+textHeight+'px;padding-left:'+imgMarginHorizontal+'px;padding-right:'+imgMarginHorizontal+'px;"' if (boolText){ divid='id="div_textlink'+intWhichSet+'"'; linkid='id="textlink'+intWhichSet+'"'; document.write('
'); document.write('WN Network'); document.write('
'); if (boolControls || boolFoot){ document.write('
'); if (boolFoot){ document.write('') } if (boolControls){ document.write('<') document.write('=') document.write('>') } document.write('
'); } } document.write('
'); document.write('
'); if(navigator.userAgent.indexOf('Windows CE')==-1){ //hack needed for pocket PC: this function has to be called in a separate script block. Otherwise function fails. Cause undetermined. Probably slow generation of HTML via JS. startRotation(intWhichSet); } }