// JavaScript Document

//Global Variables
var backgrounds = new Array();
var allcreatives = new Array();
var currentsection = "welcome";
var menuchange = false;
var currentselcreative = 0; //Sections
var currentselsection = "";


var currentplayselcreative = 0; //Playlist
var currentplayselsection = "false";


var customplaylist = false;
var currentcustom = 0;
var playlistout = false;
var menuout = true;
var doingmoving = false;
var playlistmargin = 250;
var viewedsection = "";

//var playlistmode = "showplaylist";



var searchstring = "";
var currentlylookingat = -1;
var currentlylookingatplaylist = -1;

var lastviewplaylist = false;
var searchinside = "innoall";
var previouslyviewedcreatives = new Array;

var gallerytype = true; //TRUE = INNOVATION GALLERY
var searchalreadyclicked = false;
var newsearchalreadyclicked = false;

//setTimeout("init()",100);

//Google Analytics Example
//pageTracker._trackPageview("Maximise Menu");


function init(){
//CreateDropdownWindow('My Window', '300px', true, 'FirstContent');
opacity("pagecontent", 95,0,10);
opacity("welcomemain", 0, 95, 3000);
//opacity("welcomecontainer", 0, 95, 1);
//opacity("welcometitletext", 0, 100, 1000);

//Bring in Welcome Screen
//document.getElementById("welcomemain").innerHTML = document.getElementById("actualwelcome").innerHTML;
//document.getElementById("welcometitletext").innerHTML = "Welcome";

document.getElementById("welcome").style.zIndex = 1;

document.getElementById("iframecontent").src = "blank.html";


BrowserDetect.init();

//alert(BrowserDetect.browser);
if(BrowserDetect.browser == "Chrome" | BrowserDetect.browser == "Safari"){
//Stupid Browser Settings;
	document.getElementById("welcomemain").style.padding = "0px";
	document.getElementById("welcome").style.marginTop = "20%";
	document.getElementById("welcometitletext").style.height = "19px";
	playlistmargin = 425;
	document.getElementById("leftplaylist").style.height = "50px";
	

}
if(BrowserDetect.browser == "MSIE" | BrowserDetect.browser == "Explorer"){
var array1 = getElementsByClass("bottomshadow");
for(c = 0; c < array1.length;c++){
array1[c].style.bottom = "-10px";

}
var array1 = getElementsByClass("bottomshadow2");
for(c = 0; c < array1.length;c++){
array1[c].style.bottom = "-15px";
}

//document.getElementById("mainmenubuttonall").left = "0px";
document.getElementById("rightwelcomemenu").style.marginRight="50px";
document.getElementById("minimisebottom").style.bottom;
}



//Disable Spacebar
/*
window.onkeydown=function(e){
if(e.keyCode==32){
return false;
} else if(e.keyCode == 34){
return false;
}
} */





//Set Backgrounds
//document.getElementsByTagName("html").style.overflow = "hidde";
//document.body.style.overflow = "hidden";

backgrounds[0]="url(galleryicons/sky.jpg)";
backgrounds[1]="url(galleryicons/grass.jpg)";
backgrounds[2]="url(galleryicons/water.jpg)";
backgrounds[3]="url(galleryicons/beach.jpg)";
backgrounds[4]="url(galleryicons/mountains.jpg)";
backgrounds[9]="url(galleryicons/bluebg.jpg)";
backgrounds[6]="url(galleryicons/autumn.jpg)";
backgrounds[7]="url(galleryicons/megan1.jpg)";
backgrounds[8]="url(galleryicons/orangutan.jpg)";
backgrounds[9]="url(galleryicons/london.jpg)";
backgrounds[10]="url(galleryicons/london2.jpg)";
//Set position of playlist
document.getElementById("playlistcontainer").style.top = windowSize().height + 'px';

//Sets Playlist var
	playlistcreatives = new Array;

		//Sets Up Element Titles - To be Dervived from XML


// OLD METHOD PLEASE IGNORE
//Set Creatives

//FAKE DATA FOR ENTIRE GALLERY - NEW METHOD



generategallerymenu();
if(BrowserDetect.browser == "MSIE" | BrowserDetect.browser == "Explorer"){

//document.getElementById("mainmenu").style.width = "110%";
//document.getElementById("mainmenu").style.width = windowSize().width - ((windowSize().width/100)*7) + "px";
document.getElementById("mainmenu").style.width = document.getElementById("menu").offsetWidth - ((document.getElementById("menu").offsetWidth/100)*6.3) + "px";
}





generatenewsearchmenu();

document.searchform2.newsearchtext.focus ();

generatesearchmenu();



/*
var myAddr = window.location.search;
if(myAddr.length>0){

//STRING PARSED TO IT SO POPULATE CUSTOM LIST - FAKED - TO BE TAKEN FROM DB WHEN CMS THERE
customplaylist = true;
playlistcreatives[0] = "3";
playlistcreatives[1] = "4";
playlistcreatives[2] = "8";
playlistcreatives[3] = "10";
playlistcreatives[4] = "11";

updateplaylist();
showplaylist();
moveleft("controlmenu", 0, 50);

}
*/

if(gup('viewcreative') != ""){
currentselsection = "youtube";
viewgallerycreative(gup('viewcreative'));
hideplaylist();
}
if(gup('viewplaylist') !=""){
customplaylist = true;
loadXMLDoc("loadplaylist");
currentselsection="youtube";
}
if(gup('viewsectionplaylist') !=""){
currentselsection = gup('viewsectionplaylist');
//find right creative to view?
var foundid = -1;
//alert(currentselsection);
			if(currentselsection.search("inno") == 0){
				//alert("hey");
					searchterm = currentselsection.substring(4, currentselsection.length);
						for(n=allgallerycreatives.length-1; n > 0;n--){
							var checkvar = (allgallerycreatives[n][15].toLowerCase().search(searchterm));
							if(checkvar > -1){
								if(allgallerycreatives[n][12] == 1){                            
								foundid = n;
								}
							}
						}
			}else{
				for(n=allgallerycreatives.length-1; n > 0;n--){
					//alert(allgallerycreatives[n][9].toLowerCase());
							var checkvar = (allgallerycreatives[n][9].toLowerCase()).search(currentselsection);
							//alert(checkvar);
							if(checkvar > -1){  
							
								foundid = n;
								//alert("hi");
							}
						}
				
			}
			//alert(foundid);
			if(foundid != -1){
			viewgallerycreative(foundid);
			}
//currentselsection = gup('viewsectionplaylist');
updateplaylist();


//Resizes Window
resizewelcomecheck();
//resizewelcomecheck();

}


}

function gup( name ) //Function that gets GET vars
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function opacity(id, opacStart, opacEnd, millisec) { 
   
	/*
	//speed for each frame 
    var speed = Math.round(millisec / 100); 
	//speed = 1;
	//opacStart = 94;
	//opacEnd = 95;
    var timer = 0; 
    

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
	return true;
	if(i >= opacEnd){
	menuchange = false;
	}
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
	if(i <= opacEnd){
	menuchange = false;
	}
    }  */
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
	//alert(id);
	
    var tempobject = document.getElementById(id);
	//alert(tempobject);
    tempobject.curopacity = opacity;
    var object = tempobject.style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
    
}

//Generates Window Size Information
function windowSize() {
var width = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
var height = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
var x = window.pageXOffset || (window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
var y = window.pageYOffset || (window.document.documentElement.scrollTop || window.document.body.scrollTop);
return {'width':width, 'height':height, 'x':x, 'y':y}
};


function minimisemenu(){
menuout = false;
var currentelem = document.getElementById("menucontainer");
//var currentelemcontrol = document.getElementById("control");
var currentelemsearch = document.getElementById("searchright");
clearInterval(currentelem.interval);
	//alert(currentelemcontrol.offsetTop);
	//currentelemcontrol.style.bottom = (windowSize().height - (currentelem.offsetTop+currentelem.offsetHeight))- 2 +"px";
	currentelem.style.bottom = (windowSize().height - (currentelem.offsetTop+currentelem.offsetHeight)) - 2 + "px";
	//currentelemsearch.style.bottom = (windowSize().height - (currentelem.offsetTop+currentelem.offsetHeight)) - 2 + "px";
	if((windowSize().height - currentelem.offsetTop) > 10){
	currentelem.interval = setInterval("minimisemenu()", 5); 
	}
	else{
	//Done 
	//currentelem.onclick = "maximisemenu()";
	//alert("hi");
	var minivar = document.getElementById("minimise");
	//alert(minivar.onclick);
	//minivar.onclick = new Function("maximisemenu()");
	minivar.innerHTML = "<a href='javascript:maximisemenu()'><img src='galleryicons/up_arrow.gif'></a>";
	minivar.setAttribute("onclick", "maximisemenu()");
	minivar.onclick = function() {maximisemenu()};
	//alert(minivar.onclick);
	}
}

function minimisemenubottom(){
menuout = false;
var currentelem = document.getElementById("menucontainer");
var currentelemplaylist = document.getElementById("playlistcontainer");

document.getElementById("playlist").style.top = "-80px";
document.getElementById("playlistheader").style.marginTop = "4px";
document.getElementById("playlistheader").style.top = "-6px";
//document.getElementById("playlistcontainer").style.marginTop = "4px";

var currentelemsearch = document.getElementById("searchright");
clearInterval(currentelem.interval);
currentelem.style.top = "-125px";
currentelemplaylist.style.paddingTop="0px";
//document.getElementById("minimisebottom").style.bottom = "-5px";
	//alert(currentelemcontrol.offsetTop);
/*	if(currentelemplaylist.offsetTop < 200){
	currentelemplaylist.style.top = currentelemplaylist.offsetTop - 2 + "px";
	}	
	currentelem.style.top = currentelem.offsetTop - 2 + "px";
	//currentelemsearch.style.top = currentelemsearch.offsetTop - 2 + "px";
	//alert((windowSize().height - currentelem.offsetTop));
	if(currentelem.offsetTop > -84){
	//alert(currentelem.offsetTop)
	currentelem.interval = setInterval("minimisemenubottom()", 10); 
	}
	else{
	//Done 
	//currentelem.onclick = "maximisemenu()";
	//alert("hi");
	var minivar = document.getElementById("minimisebottom");
	//alert(minivar.onclick);
	//minivar.onclick = new Function("maximisemenu()");
	minivar.innerHTML = "<a href='javascript:maximisemenubottom()'><img src='galleryicons/down_arrow.gif'></a>";
	minivar.setAttribute("onclick", "maximisemenubottom()");
	minivar.onclick = function() {maximisemenubottom()};
	//alert(minivar.onclick);
	}*/
	
	var minivar = document.getElementById("minimisebottom");
	//alert(minivar.onclick);
	//minivar.onclick = new Function("maximisemenu()");
	minivar.innerHTML = "<img src='galleryicons/down_arrow.gif'>";
	minivar.setAttribute("onclick", "maximisemenubottom()");
	minivar.onclick = function() {maximisemenubottom()};
	setplaylistheight();
	pageTracker._trackPageview("Minimise Menu");
}

function maximisemenubottom(){
menuout = true;
var currentelem = document.getElementById("menucontainer");
var currentelemplaylist = document.getElementById("playlistcontainer");



document.getElementById("playlist").style.marginTop = "";
document.getElementById("playlist").style.paddingTop = "";
document.getElementById("playlist").style.top = "";
document.getElementById("playlistheader").style.marginTop = "";
document.getElementById("playlistheader").style.top = "";
//document.getElementById("minimisebottom").style.bottom = "-5px";

var currentelemsearch = document.getElementById("searchright");
clearInterval(currentelem.interval);
currentelem.style.top = "";
currentelemplaylist.style.paddingTop="";
	//currentelemsearch.style.top= currentelemsearch.offsetTop + 2 + "px";
	/*currentelem.style.top = currentelem.offsetTop + 2 + "px";
	currentelemplaylist.style.top = currentelemplaylist.offsetTop + 2 + "px";
//alert((windowSize().height - currentelem.offsetTop));
	if(currentelem.offsetTop < -12){
	currentelem.interval = setInterval("maximisemenubottom()", 10); 
	}
	else{
	//Done
	//alert((windowSize().height - currentelem.offsetTop));
	var minivar = document.getElementById("minimisebottom");
	minivar.innerHTML = "<a href='javascript:minimisemenubottom()'><img src='galleryicons/up_arrow.gif'></a>";
	minivar.setAttribute("onclick", "minimisemenubottom()");
	minivar.onclick = function() {minimisemenubottom()};
	}*/
	
		var minivar = document.getElementById("minimisebottom");
	minivar.innerHTML = "<img src='galleryicons/up_arrow.gif'>";
	minivar.setAttribute("onclick", "minimisemenubottom()");
	minivar.onclick = function() {minimisemenubottom()};
	
	//Google Analytics
	setplaylistheight();
	pageTracker._trackPageview("Maximise Menu");

	
}

function maximisemenu(){
menuout = true;
var currentelem = document.getElementById("menucontainer");
//var currentelemcontrol = document.getElementById("control");
var currentelemsearch = document.getElementById("searchright");
clearInterval(currentelem.interval);
//currentelemsearch.style.bottom = (windowSize().height - (currentelem.offsetTop+currentelem.offsetHeight)) + 2 + "px";
//currentelemcontrol.style.bottom = (windowSize().height - (currentelem.offsetTop+currentelem.offsetHeight)) + 2 + "px";
	currentelem.style.bottom = (windowSize().height - (currentelem.offsetTop+currentelem.offsetHeight)) + 2 + "px";
//alert((windowSize().height - currentelem.offsetTop));
	if((windowSize().height - currentelem.offsetTop) < 85){
	currentelem.interval = setInterval("maximisemenu()", 10); 
	}
	else{
	//Done
	//alert((windowSize().height - currentelem.offsetTop));
	var minivar = document.getElementById("minimise");
	minivar.innerHTML = "<a href='javascript:minimisemenu()'><img src='galleryicons/down_arrow.gif'></a>";
	minivar.setAttribute("onclick", "minimisemenu()");
	minivar.onclick = function() {minimisemenu()};
	}
}



function changebg(id){
document.getElementById("wrapper").style.backgroundImage = backgrounds[id];
}

function changesection(gotid){
//check if same section
document.getElementById("welcome").style.zIndex = "220";
    document.getElementById("pagecontent").style.zIndex = "100";
document.getElementById("welcome").style.display="block";
document.getElementById("welcomebottom").style.display = "block";
	if(currentselsection == gotid){


	}
	else{
		
		//else fade old section
		//alert(currentselsection);
		//Change title

		
		//append new div
		//remove content from div

		//opacity("welcomemain", 95, 0, 500);




	var id = "welcomemain";
	var opacStart = 95;
	var opacEnd = 0;
	var millisec = 500;
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
	//setTimeout("changecontent(" + id + ")", (timer++*speed);
    } 
 


		//opacity done!
		//alert("hi");






		currentelem = document.getElementById("welcomemain");
		currentelem.interval = setInterval("checkerscript('" + gotid + "')", 100); 


		
		

	}



}

		function checkerscript(gotid){
			//alert("12");
			currentelem = document.getElementById("welcomemain");
			clearInterval(currentelem.interval);
			//alert(currentelem.style.opacity);
			if(currentelem.curopacity <= 0){
						
					var welcomemain = document.getElementById("welcomemain");
					welcomemain.innerHTML = "";
					//alert(allcreatives.length);
					for(m = 0; m < (allcreatives.length); m++){
					//alert(gotid);
					//alert(allcreatives[m][0][0]);
					if(gotid == "allcreatives"){
					   currentselsection = "allcreatives";
                        currentelem2 = document.getElementById("welcometitletext");
						currentelem2.innerHTML = "All Creatives";
						searchelem = document.getElementById("searchseaction");
						searchelem.innerHTML="All Creatives";
						
						for(n = 1; n < (allcreatives[m].length); n++){

                            generatecreative('creativemain'+n, m, n, 'welcomemain');

						}
					} else{
					if(allcreatives[m][0][0] == gotid){
						//alert(2);
						currentselsection = m;
						currentelem2 = document.getElementById("welcometitletext");
						currentelem2.innerHTML = allcreatives[m][0][1];
						searchelem = document.getElementById("searchseaction");
						searchelem.innerHTML=allcreatives[m][0][1];
						
						for(n = 1; n < (allcreatives[m].length); n++){

                            generatecreative('creativemain'+n, m, n, 'welcomemain');

						}
					}
					}
					}
				
					
					opacity("welcomemain", 0, 95, 500);


			}
			else{
			//alert("hi");
			currentelem.interval = setInterval("checkerscript('" + gotid + "')", 100); 

			}

		}








function createlightbox(content, widthvar, heightvar){

    //Create the dark area

                            var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', 'black_overlay');
							newdiv.setAttribute('class', 'black_overlay');
							newdiv.className = 'black_overlay';
							newdiv.setAttribute('onclick', 'closelightbox()');
							newdiv.onclick = function() {closelightbox()};
							document.body.appendChild(newdiv);
							newdiv.style.display='block';
    //Create the light area
                            var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', 'white_content');
							newdiv.setAttribute('class', 'white_content');
							newdiv.className = 'white_content';
							newdiv.innerHTML=content;
							newdiv.style.width=widthvar+'px';
							newdiv.style.height=heightvar+'px';
							//alert(newdiv.style.width);
							//newdiv.style.left='50%';
							//newdiv.style.top='50%';
							var marginleft = (widthvar/2*-1);
							var margintop = (heightvar/2*-1);
							
							//newdiv.setAttribute('style', 'margin-left:'+marginleft+'px; margin-top:'+margintop+'px');
							newdiv.style.marginLeft = marginleft+'px'; 
	                       	newdiv.style.marginTop = margintop+'px'; 
							document.body.appendChild(newdiv);
							newdiv.style.display='block';

}


function closelightbox(){
document.body.removeChild(document.getElementById("white_content"));
document.body.removeChild(document.getElementById("black_overlay"));

}

function showsettings(){
var settinghtml='<div id="title" class="white_content_title">Settings<div id="closebtn" onclick="closelightbox()"><img src="galleryicons/close26.gif"></a></div></div><div id="background" class="settingstype">Background</div><div id="bg1" class="settingsdiv" onclick="changebg(0)"><a href="javascript:changebg(0)"><img src="galleryicons/skyicon.jpg"></a><br>Clouds</div><div id="bg2" onclick="changebg(1)" class="settingsdiv"><a href="javascript:changebg(1)"><img src="galleryicons/grassicon.jpg"></a><br>Grass</div><div id="bg3" onclick="changebg(2)" class="settingsdiv"><a href="javascript:changebg(2)"><img src="galleryicons/waterfallicon.jpg"></a><br>Waterfall</div><div id="bg4" onclick="changebg(3)" class="settingsdiv"><a href="javascript:changebg(3)"><img src="galleryicons/beachicon.jpg"></a><br>Island</div><br><div id="bg1" class="settingsdiv" onclick="changebg(4)"><a href="javascript:changebg(4)"><img src="galleryicons/mountainsicon.jpg"></a><br>Mountains</div><div id="bg2" onclick="changebg(5)" class="settingsdiv"><a href="javascript:changebg(5)"><img src="galleryicons/blueicon.jpg"></a><br>Blue</div><div id="bg3" onclick="changebg(6)" class="settingsdiv"><a href="javascript:changebg(6)"><img src="galleryicons/autumnicon.jpg"></a><br>Autumn</div><div id="bg4" onclick="changebg(8)" class="settingsdiv"><a href="javascript:changebg(8)"><img src="galleryicons/orangutanicon.jpg"></a><br>Orangutan</div><div id="bg4" onclick="changebg(9)" class="settingsdiv"><a href="javascript:changebg(9)"><img src="galleryicons/londonicon.jpg"></a><br>London Night</div><div id="bg4" onclick="changebg(10)" class="settingsdiv"><a href="javascript:changebg(10)"><img src="galleryicons/london2icon.jpg"></a><br>London Day</div><!--<div id="style" class="settingstype">Style</div><div id="bg3" onclick="changecss(0)" class="settingsdiv"><a href="javascript:changecss(0)"><img src="galleryicons/whitestyleicon.jpg"></a><br>White</div><div id="bg3" onclick="changecss(1)" class="settingsdiv"><a href="javascript:changebg(1)"><img src="galleryicons/blackstyleicon.jpg"></a><br>Black</div><div id="style" class="settingstype">Position</div><div id="bg3" class="settingsdiv"><a href="javascript:changemenuposition(0)"><img src="galleryicons/topmenu.jpg"></a><br>Top</div><div id="bg3"class="settingsdiv"><a href="javascript:changemenuposition(1)"><img src="galleryicons/bottommenu.jpg"></a><br>Bottom</div> -->';
createlightbox(settinghtml, 400, 480);
}

function changemenuposition(position){
	currentelem =  document.getElementById('menucontainer');
	if(position==0){
		currentelem.className = "menucontainer";
		currentelems = getElementsByClass("gallerymenulistbottom");
		for(m=0;m<currentelems.length;m++){
		currentelems[m].className = "gallerymenulist";
		}
		currentelem = document.getElementById("searchinsidemenu");
		currentelem.className = "searchinsidemenu";
		currentelem = document.getElementById("welcome");
		currentelem.style.marginTop = "10%";
		currentelems = getElementsByClass("searchinsidesubmenubottom");
		for(m=0;m<currentelems.length;m++){
		currentelems[m].className = "searchinsidesubmenu";
		}
	}
	else if(position == 1){
		currentelem.className = "menucontainerbottom";
		currentelems = getElementsByClass("gallerymenulist");
		for(m=0;m<currentelems.length;m++){
		currentelems[m].className = "gallerymenulistbottom";
		}
		currentelem = document.getElementById("searchinsidemenu");
		currentelem.className = "searchinsidemenubottom";
		currentelem = document.getElementById("welcome");
		currentelem.style.marginTop = "5%";
		currentelems = getElementsByClass("searchinsidesubmenu");
		for(m=0;m<currentelems.length;m++){
		currentelems[m].className = "searchinsidesubmenubottom";
		}
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function changecss(css){
    if(css==0){ //white
        document.getElementById('ss').href = 'white.css';
        }
    else if(css==1){
        document.getElementById('ss').href = 'black.css';
        }
}

function changetonormalplaylist(){


customplaylist = false;
//updateplaylist();

}





function viewmenucreative(elem, elem2){
//alert(elem.myflag);
	//alert(elem);
	viewedsection = "custom";
		if(elem2 != undefined){
		n = elem2;
		
		} else{
		var e_out; 
		var test = typeof(window.event);
		
		if(test != "undefined"){
		n = elem.myflag;
		} else{
		n = elem
		}
		}
		//alert(test);
		
		//alert(test);
		//if(typeof(window.event)!="undefined")? e_out=event.srcElement.id : e_out=evt.target.id; 
	/*if(typeof(window.event)!="undefined"){
		 if(event.srcElement.id.length > 0){
		 e_out=event.srcElement.id; 
		 var elem = document.getElementById(e_out)
		 	n = elem.myflag;
		 }
	}else{
		var n = this.myflag;}*/
//alert(n);
customplaylist = true;
currentlylookingatplaylist = n;
//Make all unselected
//alert(n);
for(i=0; i <playlistcreatives.length;i++){
//alert(i);
document.getElementById("menuiconcustom"+i).className="creativeclass";
}

document.getElementById("menuiconcustom"+n).className="selectcreative";
var checkvar = (((allgallerycreatives[n][9]+","+allgallerycreatives[n][6]).toLowerCase())).search("youtube");
	if(checkvar > -1){
			document.getElementById("menuiconcustom"+n).className= "ytselectcreative";
}
	
	document.getElementById("next").style.display = "block";
	document.getElementById("next2").style.display = "block";
	document.getElementById("previous").style.display = "block";
	document.getElementById("previous2").style.display = "block";
	
	if (n == playlistcreatives.length-1){
				//End creative so hide right hand panel
					//document.getElementById("next").style.display = "none";
					//document.getElementById("next2").style.display = "none";
    }
	if(n == 0){
			//Start creative so hide left hand panel
					//document.getElementById("previous").style.display = "none";
					//document.getElementById("previous2").style.display = "none";
	}
	//Setup Control (i.e. Hide left and right if there).

	//alert(customplaylist);
	
    //sets iframe
    var iframevar = document.getElementById("iframecontent");
    frames['iframecontent'].location.href = allgallerycreatives[playlistcreatives[n]][3];
    //fades in iframe
    document.getElementById("pagecontent").style.zIndex = "250";
    opacity("pagecontent", 0,100,1);
	document.getElementById("welcome").style.zIndex = "201";
	document.getElementById("welcome").style.display = "none";
	
	currentplayselsection = "false";


}

function showmenusectioncustom(){
customplaylist = true;
updateplaylist();
if(playlistcreatives.length > 0){
//alert('viewing');
viewmenucreative(0, 0);
} 
}
function showmenusubsection(gotid){
				//currentelem2 = document.getElementById("welcometitletext");
					//Find Title;
					//alert("hi");
					var foundid = 0;
					currentselsection = gotid;
					
					
					for(n=0; n < allgallerycreativessections.length;n++){
						for(m=0; m < allgallerycreativessections[n].length;m++){
							if(allgallerycreativessections[n][m][0]==gotid){
								var sectionm = m;
								var sectionn = n;
							}
						}
					}
					
					//Check if Innovation Link:
					searchterm = gotid.substring(4, gotid.length);
						for(n=allgallerycreatives.length-1; n > 0;n--){
							var checkvar = ((allgallerycreatives[n][15].toLowerCase())).search(searchterm);
							if(checkvar > -1){
								if(allgallerycreatives[n][12] == 1){                            
								foundid = n;
								}
							}
						}
				
				viewgallerycreative(foundid);
				hideplaylists();
				
}
function showplaylists(){

	
	
	//Custom Playlist
	///console.log(document.getElementById("playlistclosebtn").innerHTML);
	if(document.getElementById("playlistclosebtn").innerHTML != '<img src="galleryicons/blackuparrow.gif">'){
document.getElementById("playlistclosebtn").innerHTML = "<img src='galleryicons/blackuparrow.gif'>";
	}

document.getElementById("playlistlistscontainer").style.display = "block";

/*
		if(vardiv.addEventListener){ 
		vardiv1.addEventListener('mouseout',hideplaylists,false) ; 
		}else{ 
		vardiv1.attachEvent('onmouseleave',function(){hideplaylists('var')}); 
		}  */
		
		var currentelem = document.getElementById("playlistheader");
		currentelem.style.backgroundColor = "#EBEBEB";
		currentelem.style.color = "#000000";
		currentelem.style.backgroundImage = "url(galleryicons/trans.gif)";
		document.getElementById("selectedplaylisttitle").style.color = "#000000";
		
}

function highlightplaylists(elem){
	if(elem.length > 0){
		var e_out; 
		if(typeof(window.event)!="undefined"){
		 if(event.srcElement.id.length > 0){
		 e_out=event.srcElement.id; 
		 var elem = document.getElementById(e_out)
		 	elem = elem.myflag;
		 }
		}
	}else{
	var elem = this.myflag;	}
	if(document.getElementById("playlistlistsitem"+elem) != null){
	var currentelem = document.getElementById("playlistlistsitem"+elem);
	currentelem.style.backgroundColor = "#CCCCCC";
	}
	//showplaylists();
}

function unhighlightplaylists(elem){
	if(elem.length > 0){
		var e_out; 
		if(typeof(window.event)!="undefined"){
		 if(event.srcElement.id.length > 0){
		 e_out=event.srcElement.id; 
		 var elem = document.getElementById(e_out)
		 	elem = elem.myflag;
		 }
		}
	}else{
	var elem = this.myflag;	}
	//alert(elem);
	//alert(document.getElementById("playlistlistsitem"+elem));
	if(document.getElementById("playlistlistsitem"+elem) != null){
	var currentelem = document.getElementById("playlistlistsitem"+elem);
	currentelem.style.backgroundColor = "";
	}
}


function hideplaylists(){
	//console.log("hide");
	var el = document.getElementById('playlistlistscontainer');
	el.style.display = "none";
	var vardiv = document.getElementById("selectedplaylisttitle");
	vardiv.setAttribute("onclick", "javascript:showplaylists()");
	vardiv.onclick = function(){showplaylists()};	
	
	//console.log("inplaylist");
//alert("hi");
/*
if(el.length != 0){
for(i=0;i== el.length-1;i++){
	//console.log(i);
		el[i].parentNode.removeChild(el[i]);
	}
} */
document.getElementById("playlistclosebtn").innerHTML = "<img src='galleryicons/whitedownarrow.gif'>";
var currentelem = document.getElementById("playlistheader");
		currentelem.style.backgroundColor = "";
		currentelem.style.borderRight = "";
		currentelem.style.color = "#FFFFFF";
		currentelem.style.backgroundImage = "url(galleryicons/menubggreen.gif)";
		document.getElementById("selectedplaylisttitle").style.color = "#FFFFFF";

}

function updateplaylist(n){

	//playlist
    var playlistdiv = document.getElementById("playlist");
	var playlisttitlediv = document.getElementById("playlistheader");
	
	
	//Add control panel	
	playlistdiv.innerHTML = "";
	playlisttitlediv.innerHTML = "";
	
    if(customplaylist == true){//Dont make changes to the playlistplay
	
	var vardiv1 = document.createElement("div");
	vardiv1.setAttribute("id", "selectedplaylisttitle");
	vardiv1.setAttribute("onclick", "javascript:showplaylists()");
	vardiv1.onclick = function() {showplaylists()};
	//var vara1 = document.createElement("a");
	//vara1.setAttribute("href", "javascript:hideplaylist()");
	vardiv1.appendChild(document.createTextNode("Custom Playlist"));
	//vardiv1.appendChild(vara1); 
	playlisttitlediv.appendChild(vardiv1); 
	var vardiv2 = document.createElement("div");
	vardiv2.className = "playlistclosebtn";
	vardiv2.id = "playlistclosebtn";
	vardiv2.innerHTML = "<img src='galleryicons/whitedownarrow.gif'>";
	vardiv1.appendChild(vardiv2);
	
							var vardiv3 = document.getElementById("selectedplaylisttitle");
							vardiv3.setAttribute("onclick", "javascript:hideplaylists()");
							vardiv3.onclick = function(){hideplaylists()};
							var vardiv4 = document.createElement("div");
							vardiv4.setAttribute("id", "playlistlistscontainer");
							vardiv4.setAttribute("name", "playlistlistscontainer");
							vardiv4.style.display="none";
							vardiv3.appendChild(vardiv4);
	
							var newdiv2 = document.createElement('div');
							newdiv2.className = "playlistlistsitem";
							newdiv2.setAttribute('id', 'playlistlistsitemcustom');
							newa = document.createElement('a');
							newa.href = "javascript:showmenusectioncustom()";
							newa.innerHTML = "<img id='changesectionimg"+j+"' src='galleryicons/menublackbox.gif'>Custom Playlist";
							newdiv2.setAttribute("onclick", "javascript:showmenusectioncustom()");
							newdiv2.appendChild(newa);
							vardiv4.appendChild(newdiv2); 
							if(vardiv4.addEventListener){ 
									newdiv2.addEventListener('mouseout', unhighlightplaylists, false);
									newdiv2.addEventListener('mouseover', highlightplaylists,false);
									newdiv2.myflag = 'custom';
							}else{  //IE
									newdiv2.attachEvent('onmouseleave', function(){unhighlightplaylists("var")}, false);
									newdiv2.attachEvent('onmouseover',function(){highlightplaylists("var")}, false);
									newdiv2.myflag = 'custom';
							} 
	
							for(j=1; j < allgallerycreativessections[0].length; j++){
								var newdiv2 = document.createElement('div');
								newdiv2.className = "playlistlistsitem";
								newdiv2.setAttribute('id', 'playlistlistsitem'+j);
								newa = document.createElement('a');
								newa.href = "javascript:showmenusubsection('"+ allgallerycreativessections[0][j][0]+"');hideplaylists();";
								newa.innerHTML = "<img id='changesectionimg"+j+"' src='galleryicons/menublackbox.gif'>"+allgallerycreativessections[0][j][1] + " Playlist";
								newdiv2.setAttribute("onclick", "javascript:showmenusubsection('"+ allgallerycreativessections[0][j][0]+"');hideplaylists();");
								newdiv2.appendChild(newa);
								vardiv4.appendChild(newdiv2);
								if(newdiv2.addEventListener){ 
										newdiv2.addEventListener('mouseout', unhighlightplaylists, false);
										newdiv2.addEventListener('mouseover', highlightplaylists,false);
										newdiv2.myflag = j;
								}else{  //IE
								newdiv2.attachEvent('onmouseleave', function(){unhighlightplaylists("var")}, false);
								newdiv2.attachEvent('onmouseover',function(){highlightplaylists("var")}, false);
								newdiv2.myflag = j;
								} 
		
							}
						
						
						
						if(vardiv3.addEventListener){ 
							vardiv3.addEventListener('mouseout', hideplaylists, false);
							vardiv3.addEventListener('mouseover', showplaylists,false);
						}else{  //IE
							vardiv3.attachEvent('onmouseleave', function(){hideplaylists("var")}, false);
							vardiv3.attachEvent('onmouseover',function(){showplaylists("var")}, false);
							} 
	
	
	if(playlistcreatives.length > 0){
	
	
	var playlistfuncontainer = document.createElement("div");
	playlistfuncontainer.className = "playlistfuncontainer";
	playlistfuncontainer.id = "playlistfuncontainer";
	playlistfuncontainer.setAttribute = ("id", "playlistfuncontainer");
	var playlistfunplay = document.createElement("div");
	playlistfunplay.className = "playlistoptionsplay";
	playlistfunplay.innerHTML="<a href='javascript:playplaylist()'  title='View Fullscreen'>View<br><img src='galleryicons/fullscreen.jpg'></a>";
	var playlistfunemail = document.createElement("div");
	playlistfunemail.id = "playlistoptionsemail";
	playlistfunemail.className = "playlistoptionsemail";
	playlistfunemail.innerHTML="<a href='javascript:emailplaylist()'  title='Email Playlist'><img src='galleryicons/mail.jpg'></a>";
	var playlistfunerase = document.createElement("div");
	playlistfunerase.className = "playlistoptionserase";
	playlistfunerase.innerHTML="<a href='javascript:clearplaylist()'  title='Clear Playlist'>Clear<br><img src='galleryicons/clear.jpg'></a>";
	//var playlistfunback = document.createElement("div");
	//playlistfunback.className = "playlistoptionsback";
//	playlistfunback.innerHTML="<a href='javascript:changetonormalplaylist()'>Back<br><img src='galleryicons/clear.jpg'></a>";
	//playlistfuncontainer.appendChild(playlistfunerase);
	//playlistfuncontainer.appendChild(playlistfunplay);
	playlisttitlediv.appendChild(playlistfunemail);
	//vardiv1.appendChild(playlistfuncontainer);
	//playlistdiv.appendChild(playlistfunback);
	}
	
	//OLD
    // playlistdiv.innerHTML = "<div id='playlisttitle' onclick='playlisttosection()'><a href='javascript:playlisttosection()'>Section Playlist </a></div><div id='playlisttitle' onclick='playlisttorecent()'><a href='javascript:playlisttorecent()(0)'>History Playlist</a></div><div id='selectedplaylisttitle' onclick='hideplaylist()'><a href='javascript:hideplaylist()'>Custom Playlist</a></div>";
						//alert(2);
						var foundsomecreatives = false;
						for(q = 0; q < (playlistcreatives.length); q++){

                            generategallerycreative('menuiconcustom'+q, playlistcreatives[q], 'playlist');
							//Check if not innovative creative;
							
														
							
							var currentmenuitem = document.getElementById("menuiconcustom"+q);
							//Change Clickthrough code
							//alert(currentmenuitem.childNodes[4].childNodes[0].innerHTML);
							if(BrowserDetect.browser == "MSIE"|BrowserDetect.browser == "Explorer"){
							//alert("ie");
							currentmenuitem.childNodes[3].onclick = function(){viewmenucreative(this)}; 
							currentmenuitem.childNodes[3].setAttribute("myflag", q);
							} else{
							currentmenuitem.childNodes[3].setAttribute("onclick", "viewmenucreative("+q+")");
							}
							
							if(BrowserDetect.browser == "MSIE"|BrowserDetect.browser == "Explorer"){
							currentmenuitem.childNodes[4].onclick = function(){viewmenucreative(this)}; 
							currentmenuitem.childNodes[4].setAttribute("myflag", q);
							} else {
							currentmenuitem.childNodes[4].setAttribute("onclick", "viewmenucreative("+q+")");  }
							
							//currentmenuitem.childNodes[4].setAttribute("onclick", "javascript:viewmenucreative("+q+")");

							currentmenuitem.style.position = "absolute";
							
							
							
							//currentmenuitem.style.top = document.getElementById("playlistfuncontainer").offsetTop + 50 + 100*q + "px";
							currentmenuitem.style.top = 5 + 100*q + "px";
							//alert(currentlylookingatplaylist);
							if(q == currentlylookingatplaylist){
							currentmenuitem.className = "selectcreative";
							
							var checkvar = (((allgallerycreatives[n][9]+","+allgallerycreatives[n][6]).toLowerCase())).search("youtube");
							if(checkvar > -1){
								currentmenuitem.className = "ytselectcreative";
							}
							
							}
							
							var varnewdiv = document.createElement('div');
							varnewdiv.setAttribute('id', 'divsettings'+q);
							varnewdiv.className = "customcreativesettings";
							
							currentmenuitem.appendChild(varnewdiv);
							
                            var newdiv2 = document.createElement('div');
  							newdiv2.setAttribute('id', 'removebtnmain'+q);
							newdiv2.setAttribute('class', 'removebtnicon');
							newdiv2.className = 'removebtnicon';
							//newdiv2.setAttribute('onclick', 'removecreative('+q+')'); //WONT WORK IE
							//newdiv2.onclick = function(){removecreative("sometext"+q)};
							newdiv2.innerHTML="<a href='javascript:removecreative("+q+")'><img src='galleryicons/minus.gif'></a>";
							varnewdiv.appendChild(newdiv2);
							var newdiv2 = document.createElement('div');
  							newdiv2.setAttribute('id', 'moveupbtnmain'+q);
							newdiv2.setAttribute('class', 'moveupbtnicon');
							newdiv2.className = 'moveupbtnicon';
							//newdiv2.onclick = function(){moveupcreative(q)}; //was q
							//newdiv2.setAttribute('onclick', 'moveupcreative('+q+')'); //WONT WORK IE
							
							
							if(q!=0){
							newdiv2.innerHTML="<a href='javascript:moveupcreative("+q+")'><img src='galleryicons/green_up_arrow.gif'></a>";
							varnewdiv.appendChild(newdiv2);
							}else{
							newdiv2.innerHTML="<img src='galleryicons/up_arrow_grey.gif'>";
							varnewdiv.appendChild(newdiv2);
							}
							var newdiv2 = document.createElement('div');
  							newdiv2.setAttribute('id', 'movedownbtnmain'+q);
							newdiv2.setAttribute('class', 'movedownbtnicon');
							newdiv2.className = 'movedownbtnicon';
							//newdiv2.setAttribute('onclick', 'movedowncreative('+q+')'); //WONT WORK IE
							
							if(q != playlistcreatives.length-1){
							newdiv2.innerHTML="<a href='javascript:movedowncreative("+q+")'><img src='galleryicons/green_down_arrow.gif'></a>";
							varnewdiv.appendChild(newdiv2);
							} else{
							newdiv2.innerHTML="<img src='galleryicons/down_arrow_grey.gif'>";
							varnewdiv.appendChild(newdiv2);
							}
							foundsomecreatives = true;
							
							//Sets clicking on the creative to change the playlist var
							currentmenuitem.setAttribute("onclick", "currentcustom = "+(q-1)+";");
							//alert(currentcustom);
							
							
							
						}
						//if(foundsomecreatives == false){
						//Add Some info for user
						/*
						    var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', "addcreativespeal");
							newdiv.setAttribute('class', 'creativeclass');
							newdiv.className = 'creativeclass';
							newdiv.style.left = "2px";
							newdiv.style.top="50px";
							newdiv.style.width = "140px";
							newdiv.style.height = "70px";
							newdiv.innerHTML = "To add creatives to this playlist please select the '+' symbol next to each creative.";
							playlistdiv.appendChild(newdiv);
							
							var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', "removecreativespeal");
							newdiv.setAttribute('class', 'creativeclass');
							newdiv.className = 'creativeclass';
							newdiv.style.left = "2px";
							newdiv.style.top="50px";
							newdiv.style.width = "140px";
							newdiv.style.height = "70px";
							newdiv.innerHTML = "To remove creatives in this playlist please select the '-' symbol next to each creative.";
							playlistdiv.appendChild(newdiv);
							
							var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', "removecreativespeal");
							newdiv.setAttribute('class', 'creativeclass');
							newdiv.className = 'creativeclass';
							newdiv.style.left = "2px";
							newdiv.style.top="50px";
							newdiv.style.width = "140px";
							newdiv.style.height = "70px";
							newdiv.innerHTML = "To move creatives in this playlist please select the '<' & '>' symbols on each creative.";
							playlistdiv.appendChild(newdiv);
							*/
							//}s
     
	 
    
    }else if(lastviewplaylist == true){ //View Recent creatives - REMOVED!!!!!!!!!!!
	
	playlisttitlediv.innerHTML = "<div id='playlisttitle' onclick='playlisttosection()'><a href='javascript:playlisttosection()'>Section Playlist</a></div><div id='playlisttitle' onclick='playlisttocustom()'><a href='javascript:playlisttocustom()'>Custom Playlist</a></div><div id='selectedplaylisttitle' onclick='hideplaylist()'><a href='javascript:hideplaylist()'>History Playlist</a></div>";

		for(w=0; w < previouslyviewedcreatives.length;w++){
		//alert(previouslyviewedcreatives[w]);
					
                    generategallerycreative('menuiconcustom'+w, previouslyviewedcreatives[w], 'playlist');
		
		}

	
	}
    else{
    //remove current items in playlist
					//alert(gotid);
					//alert(allcreatives[m][0][0]);
					
					//Check if Innovation
					//for(allgallerycreative
					
					
					
					//var checkifsearch = currentselsection
					
					if(currentselsection == "innoall"){ //Show all innovation gallery ones
					   //currentselsection = -1;
					   //alert("3");
                        currentelem2 = document.getElementById("welcometitletext");
						currentelem2.innerHTML = "All Creatives";
						//
						
						
						for(n=0;n<allgallerycreatives.length;n++){
						//alert(allgallerycreatives[n][10]);
						var checkvar = (allgallerycreatives[n][9].toLowerCase()+","+allgallerycreatives[n][8].toLowerCase()+","+allgallerycreatives[n][13].toLowerCase()+","+allgallerycreatives[n][5].toLowerCase()).search(currentselsection);
							if(checkvar > -1){
							generategallerycreative('creativemain'+n, n, 'welcomemain');
							}

						}
						
					}else if(currentselsection.search("searchfor") == 0){
					
					var searchstring = currentselsection.substring(9, currentselsection.length);
					//alert(searchstring);
					
					//Search Result
					
											var vardiv1 = document.createElement("div");
						vardiv1.setAttribute("id", "selectedplaylisttitle");
						//var vara1 = document.createElement("a");
						vardiv1.setAttribute("onclick", "javascript:showplaylists()");
						vardiv1.onclick = function() {showplaylists()};
						//vara1.setAttribute("href", "");
						vardiv1.appendChild(document.createTextNode("Search Results"));
						//vardiv1.appendChild(vara1);
						playlisttitlediv.appendChild(vardiv1); 
						var vardiv2 = document.createElement("div");
						vardiv2.className = "playlistclosebtn";
						vardiv2.id = "playlistclosebtn";
						vardiv2.innerHTML = "<img src='galleryicons/whitedownarrow.gif'>";
						vardiv1.appendChild(vardiv2);
						
						
						
						
							var vardiv3 = document.getElementById("selectedplaylisttitle");
							vardiv3.setAttribute("onclick", "javascript:hideplaylists()");
							vardiv3.onclick = function(){hideplaylists()};
							var vardiv4 = document.createElement("div");
							vardiv4.setAttribute("id", "playlistlistscontainer");
							vardiv4.setAttribute("name", "playlistlistscontainer");
							vardiv4.style.display="none";
							vardiv3.appendChild(vardiv4);
	
							var newdiv2 = document.createElement('div');
							newdiv2.className = "playlistlistsitem";
							newdiv2.setAttribute('id', 'playlistlistsitemcustom');
							newa = document.createElement('a');
							newa.href = "javascript:showmenusectioncustom()";
							newa.innerHTML = "<img id='changesectionimg"+j+"' src='galleryicons/menublackbox.gif'>Custom Playlist";
							newdiv2.setAttribute("onclick", "javascript:showmenusectioncustom()");
							newdiv2.appendChild(newa);
							vardiv4.appendChild(newdiv2); 
							if(vardiv4.addEventListener){ 
									newdiv2.addEventListener('mouseout', unhighlightplaylists, false);
									newdiv2.addEventListener('mouseover', highlightplaylists,false);
									newdiv2.myflag = 'custom';
							}else{  //IE
									newdiv2.attachEvent('onmouseleave', function(){unhighlightplaylists("var")}, false);
									newdiv2.attachEvent('onmouseover',function(){highlightplaylists("var")}, false);
									newdiv2.myflag = 'custom';
							} 
	
							for(j=1; j < allgallerycreativessections[0].length; j++){
								var newdiv2 = document.createElement('div');
								newdiv2.className = "playlistlistsitem";
								newdiv2.setAttribute('id', 'playlistlistsitem'+j);
								newa = document.createElement('a');
								newa.href = "javascript:showmenusubsection('"+ allgallerycreativessections[0][j][0]+"')";
								newa.innerHTML = "<img id='changesectionimg"+j+"' src='galleryicons/menublackbox.gif'>"+allgallerycreativessections[0][j][1] + " Playlist";
								newdiv2.setAttribute("onclick", "javascript:showmenusubsection('"+ allgallerycreativessections[0][j][0]+"')");
								newdiv2.appendChild(newa);
								vardiv4.appendChild(newdiv2);
								if(newdiv2.addEventListener){ 
										newdiv2.addEventListener('mouseout', unhighlightplaylists, false);
										newdiv2.addEventListener('mouseover', highlightplaylists,false);
										newdiv2.myflag = j;
								}else{  //IE
								newdiv2.attachEvent('onmouseleave', function(){unhighlightplaylists("var")}, false);
								newdiv2.attachEvent('onmouseover',function(){highlightplaylists("var")}, false);
								newdiv2.myflag = j;
								} 
		
							}
						
						
						
						if(vardiv3.addEventListener){ 
							vardiv3.addEventListener('mouseout', hideplaylists, false);
							vardiv3.addEventListener('mouseover', showplaylists,false);
						}else{  //IE
							vardiv3.attachEvent('onmouseleave', function(){hideplaylists("var")}, false);
							vardiv3.attachEvent('onmouseover',function(){showplaylists("var")}, false);
							} 
						
						
						
						
						
							var playlistfuncontainer = document.createElement("div");
							playlistfuncontainer.className = "playlistfuncontainer";
							playlistfuncontainer.id = "playlistfuncontainer";
							playlistfuncontainer.setAttribute = ("id", "playlistfuncontainer");
							var playlistfunplay = document.createElement("div");
							playlistfunplay.className = "playlistoptionsplay";

							playlistfunplay.innerHTML="<a href='javascript:playplaylist()' title='View Fullscreen'>View<br><img src='galleryicons/fullscreen.jpg'  alt='Fullscreen'></a>";
							var playlistfunemail = document.createElement("div");
							playlistfunemail.id = "playlistoptionsemail";
							playlistfunemail.className = "playlistoptionsemail";
							var quickvar = '"'+currentselsection+'"';
							playlistfunemail.innerHTML="";
							var playlistfunerase = document.createElement("div");
							playlistfunerase.className = "playlistoptionserase";
							playlistfunerase.innerHTML="<a href='javascript:clearplaylist()' title='Clear Playlist'>Clear<br><img src='galleryicons/clear.jpg'></a>";
							//playlistfuncontainer.appendChild(playlistfunerase);
							//playlistfuncontainer.appendChild(playlistfunplay);
							playlisttitlediv.appendChild(playlistfunemail);
					

						
						
						
						/*playlisttitlediv.appendChild(vardiv1); 
						var vardiv2 = document.createElement("div");
						vardiv2.className = "playlistclosebtn";
						vardiv2.id = "playlistclosebtn";
						vardiv2.innerHTML = "<img src='galleryicons/whitedownarrow.gif'>";
						vardiv1.appendChild(vardiv2); */
						
						

						
						

						for(n=0;n<allgallerycreatives.length-1;n++){
							//alert("hi");
		//var checkvar = (allgallerycreatives[n][9].toLowerCase()+","+allgallerycreatives[n][8].toLowerCase()+","+allgallerycreatives[n][13].toLowerCase()+","+allgallerycreatives[n][5].toLowerCase()).search(searchstring);
		
						var checkvar = (allgallerycreatives[n][7].toLowerCase()+","+allgallerycreatives[n][2].toLowerCase()+","+allgallerycreatives[n][1].toLowerCase()+","+allgallerycreatives[n][0].toLowerCase()+","+allgallerycreatives[n][9].toLowerCase()+","+allgallerycreatives[n][8].toLowerCase()+","+allgallerycreatives[n][13].toLowerCase()+","+allgallerycreatives[n][5].toLowerCase()).search(searchstring);
		
		
								if(checkvar > -1){
								generategallerycreative('creativeplaylist'+n, n, 'playlist');
								foundresults = true;
								//alert("hi");
								if(n == currentlylookingat){
									var currentmenuitem = document.getElementById('creativeplaylist'+n);
										currentmenuitem.className = "selectcreative";
										//alert(n);
										var checkvar = (((allgallerycreatives[n][9]+","+allgallerycreatives[n][6]).toLowerCase())).search("youtube");
							if(checkvar > -1){
								currentmenuitem.className = "ytselectcreative";
							}
								}
								
								}
							
							//}

						}
					
					}
					else{
					
					
					//currentelem2 = document.getElementById("welcometitletext");
					//Find Title;
					var title;
					for(n=0; n < allgallerycreativessections.length;n++){
						for(m=0; m < allgallerycreativessections[n].length;m++){
							if(allgallerycreativessections[n][m][0]==currentselsection){
								
								title = allgallerycreativessections[n][m][1];
							}
						}
					}
					
					
						var vardiv1 = document.createElement("div");
						vardiv1.setAttribute("id", "selectedplaylisttitle");
						//var vara1 = document.createElement("a");
						vardiv1.setAttribute("onclick", "javascript:showplaylists()");
						vardiv1.onclick = function() {showplaylists()};
						//vara1.setAttribute("href", "");
						vardiv1.appendChild(document.createTextNode(title + " Playlist"));
						//vardiv1.appendChild(vara1);
						playlisttitlediv.appendChild(vardiv1); 
						var vardiv2 = document.createElement("div");
						vardiv2.className = "playlistclosebtn";
						vardiv2.id = "playlistclosebtn";
						vardiv2.innerHTML = "<img src='galleryicons/whitedownarrow.gif'>";
						vardiv1.appendChild(vardiv2);
						
						
						
						
							var vardiv3 = document.getElementById("selectedplaylisttitle");
							vardiv3.setAttribute("onclick", "javascript:hideplaylists()");
							vardiv3.onclick = function(){hideplaylists()};
							var vardiv4 = document.createElement("div");
							vardiv4.setAttribute("id", "playlistlistscontainer");
							vardiv4.setAttribute("name", "playlistlistscontainer");
							vardiv4.style.display="none";
							vardiv3.appendChild(vardiv4);
	
							var newdiv2 = document.createElement('div');
							newdiv2.className = "playlistlistsitem";
							newdiv2.setAttribute('id', 'playlistlistsitemcustom');
							newa = document.createElement('a');
							newa.href = "javascript:showmenusectioncustom()";
							newa.innerHTML = "<img id='changesectionimg"+j+"' src='galleryicons/menublackbox.gif'>Custom Playlist";
							newdiv2.setAttribute("onclick", "javascript:showmenusectioncustom()");
							newdiv2.appendChild(newa);
							vardiv4.appendChild(newdiv2); 
							if(vardiv4.addEventListener){ 
									newdiv2.addEventListener('mouseout', unhighlightplaylists, false);
									newdiv2.addEventListener('mouseover', highlightplaylists,false);
									newdiv2.myflag = 'custom';
							}else{  //IE
									newdiv2.attachEvent('onmouseleave', function(){unhighlightplaylists("var")}, false);
									newdiv2.attachEvent('onmouseover',function(){highlightplaylists("var")}, false);
									newdiv2.myflag = 'custom';
							} 
	
							for(j=1; j < allgallerycreativessections[0].length; j++){
								var newdiv2 = document.createElement('div');
								newdiv2.className = "playlistlistsitem";
								newdiv2.setAttribute('id', 'playlistlistsitem'+j);
								newa = document.createElement('a');
								newa.href = "javascript:showmenusubsection('"+ allgallerycreativessections[0][j][0]+"')";
								newa.innerHTML = "<img id='changesectionimg"+j+"' src='galleryicons/menublackbox.gif'>"+allgallerycreativessections[0][j][1] + " Playlist";
								newdiv2.setAttribute("onclick", "javascript:showmenusubsection('"+ allgallerycreativessections[0][j][0]+"')");
								newdiv2.appendChild(newa);
								vardiv4.appendChild(newdiv2);
								if(newdiv2.addEventListener){ 
										newdiv2.addEventListener('mouseout', unhighlightplaylists, false);
										newdiv2.addEventListener('mouseover', highlightplaylists,false);
										newdiv2.myflag = j;
								}else{  //IE
								newdiv2.attachEvent('onmouseleave', function(){unhighlightplaylists("var")}, false);
								newdiv2.attachEvent('onmouseover',function(){highlightplaylists("var")}, false);
								newdiv2.myflag = j;
								} 
		
							}
						
						
						
						if(vardiv3.addEventListener){ 
							vardiv3.addEventListener('mouseout', hideplaylists, false);
							vardiv3.addEventListener('mouseover', showplaylists,false);
							vardiv3.addEventListener('click', hideplaylists,false);
						}else{  //IE
							vardiv3.attachEvent('onmouseleave', function(){hideplaylists("var")}, false);
							vardiv3.attachEvent('onmouseover',function(){showplaylists("var")}, false);
							} 
						
						
						
						
						
							var playlistfuncontainer = document.createElement("div");
							playlistfuncontainer.className = "playlistfuncontainer";
							playlistfuncontainer.id = "playlistfuncontainer";
							playlistfuncontainer.setAttribute = ("id", "playlistfuncontainer");
							var playlistfunplay = document.createElement("div");
							playlistfunplay.className = "playlistoptionsplay";

							playlistfunplay.innerHTML="<a href='javascript:playplaylist()' title='View Fullscreen'>View<br><img src='galleryicons/fullscreen.jpg'  alt='Fullscreen'></a>";
							var playlistfunemail = document.createElement("div");
							playlistfunemail.id = "playlistoptionsemail";
							playlistfunemail.className = "playlistoptionsemail";
							var quickvar = '"'+currentselsection+'"';
							playlistfunemail.innerHTML="<a href='javascript:emailplaylist("+quickvar+")' title='Email Playlist'><img src='galleryicons/mail.jpg'></a>";
							var playlistfunerase = document.createElement("div");
							playlistfunerase.className = "playlistoptionserase";
							playlistfunerase.innerHTML="<a href='javascript:clearplaylist()' title='Clear Playlist'>Clear<br><img src='galleryicons/clear.jpg'></a>";
							//playlistfuncontainer.appendChild(playlistfunerase);
							//playlistfuncontainer.appendChild(playlistfunplay);
							playlisttitlediv.appendChild(playlistfunemail);
							//playlisttitlediv.appendChild(playlistfuncontainer);
						
						
					
					//OLD METHOD
					//playlistdiv.innerHTML = "<div id='playlisttitle' onclick='playlisttorecent()'><a href='javascript:playlisttorecent()'>History Playlist</a></div><div id='playlisttitle' onclick='playlisttocustom()''><a href='javascript:playlisttocustom()'>Custom Playlist</a></div><div id='selectedplaylisttitle'  onclick='hideplaylist()'><a href='javascript:hideplaylist()'>" + title + " Playlist</a></div> "
						//alert(2);
					
					
					
					
					//Check if Innovation Link:
					if(currentselsection.search("inno") == 0){
					//Check 10th element]
						
						currentselsectiontemp = currentselsection.substring(4, currentselsection.length);
						for(n=0; n < allgallerycreatives.length;n++){
							if(allgallerycreatives[n][12] == 1){	
								var checkvar = (allgallerycreatives[n][15].toLowerCase().search(currentselsectiontemp));
								//if(checkvar > -1){	
								//var checkvar = (allgallerycreatives[n][15].search(currentselsectiontemp));
							if(checkvar > -1){
								
                            generategallerycreative('creativeplaylist'+n, n, 'playlist');
							var currentmenuitem = document.getElementById('creativeplaylist'+n);
									if(n == currentlylookingat){
										currentmenuitem.className = "selectcreative";
										
										var checkvar = (((allgallerycreatives[n][9]+","+allgallerycreatives[n][6]).toLowerCase())).search("youtube");
										if(checkvar > -1){
											currentmenuitem.className = "ytselectcreative";
										}
										
										}
                            	foundresults = true;
								}
							}
						}
						//currentselsection = "inno"+currentselsection;				
					
					}
					else{ //Check normal tags
					
						for(n=0; n < allgallerycreatives.length;n++){
							var checkvar = (allgallerycreatives[n][9].toLowerCase()+","+allgallerycreatives[n][8].toLowerCase()+","+allgallerycreatives[n][13].toLowerCase()+","+allgallerycreatives[n][5].toLowerCase()).search(currentselsection);
								if(checkvar > -1){
                            		generategallerycreative('creativeplaylist'+n, n, 'playlist');
									var currentmenuitem = document.getElementById('creativeplaylist'+n);
									if(n == currentlylookingat){
										currentmenuitem.className = "selectcreative";
										
										var checkvar = (((allgallerycreatives[n][9]+","+allgallerycreatives[n][6]).toLowerCase())).search("youtube");
										if(checkvar > -1){
											currentmenuitem.className = "ytselectcreative";
										}
									}
									
                            	foundresults = true;
							}
						}
					}
					}

    
    
    }  
	//playlistdiv.innerHTML = playlistdiv.innerHTML + "<br><br>";
    
	if(BrowserDetect.browser == "Chrome" | BrowserDetect.browser == "Safari"){
		document.getElementById("playlistoptionsemail").style.width = "15px";
		document.getElementById("playlistoptionsemail").style.height = "16px";
	}
	
	


}

/*
function newfocus(id){
	amount = 40;
	var newcreative = document.getElementById("menuicon" + id);
	newcreative.style.border = "2px solid #DDDDDD";
	var oldcreative = document.getElementById("menuicon" + currentcreative);
	oldcreative.style.border = "none";
	if(id == currentselcreative){
	//Do Nothing
	}
	else{
//Remove all but one above creative by fade
	var amountmoved = id - currentselcreative - 1;
		for(k = (id-2); k > (currentcreative-1); k=k-1){
			//alert(i);
			
			//alert(currentcreative-1);
			var checkcreate = document.getElementById("menuicon" + k);
			checkcreate.style.zIndex = 20;
			//alert("fallloop" + k);
			opacity("menuicon" + k, 100, 0, 1000);	
					

		}
	//}
//Moves all other creatives up
		for(j = (id -1); j < (allcreatives.length-1); j++){
			//alert(j);
			var checkcreate = document.getElementById("menuicon" + j);
			moveup("menuicon" + j, checkcreate.offsetTop - (100*amountmoved), amount);
		}

//Ad more creatives to bottom if required - Later version
var iframevar = document.getElementById("iframecontent");
frames['iframecontent'].location.href = "creatives/" + allcreatives[currentselsection ][id][3];
currentselcreative = id;
	}

}
*/
function viewgallerycreative(n, m){
changetonormalplaylist();

viewedsection = currentselsection;

    //Sets menu up if not the same
	//gallerytype = false; //SETS TO ALL GALLERY
	
	
	/*
	if(previouslyviewedcreatives.length > 4){
	//remove 1 and keep replacing
		for(w=0;w<previouslyviewedcreatives.length-1;w++){
		previouslyviewedcreatives[w]=previouslyviewedcreatives[w+1];
		}
		previouslyviewedcreatives[w] = n; //Only one var means its not innovation
	
	}else{ //Add on to end 
	previouslyviewedcreatives[previouslyviewedcreatives.length] = n;	
	
	}

 if(customplaylist == false | currentplayselsection == "true"){
    //currentselsection = "fullgallery";
	currentselcreative = n;
	currentlylookingat = n;
	//alert("hi");
	
    }
    else{
	//if(m == "undefined"){
	//currentlylookingatplaylist = n;
	//currentplayselcreative = n;
	//}else{
	//currentlylookingatplaylist = m;
	//currentplayselcreative = m;
	//}

	n = playlistcreatives[n-1];
    }  */
	currentselcreative = n;
	currentlylookingat = n;
	currentplayselcreative = n;
	updateplaylist(n);
	showplaylist();
	
	
	document.getElementById("next").style.display = "block";
	document.getElementById("next2").style.display = "block";
	document.getElementById("previous").style.display = "block";
	document.getElementById("previous2").style.display = "block";
	
	//Setup Control (i.e. Hide left and right if there).

	//alert(customplaylist);
	
	//if(gup('viewcreative') == ""){
	
	

	//alert('hi');

	if(currentselsection == "innoall"){
	hideplaylist();
	}

		
		//Find Section
		var lastcreative = -1;
		var firstcreative = -1;
		//var nextfound = "false"; //Var to check if theres another creative
		for(i=0; i<allgallerycreatives.length-1; i++){
		//search for inno
		//alert("hi");
			var tempsearch = currentselsection.search("inno");
			if(tempsearch == 0){
			//Inno Creative
				currentselsectiontemp = currentselsection.substring(4, currentselsection.length);
				if(allgallerycreatives[n][12] == 1){	
				
				//var tempsearch = allgallerycreatives[i][9].toLowerCase().search(currentselsectiontemp);
				var tempsearch = (allgallerycreatives[n][15].toLowerCase().search(currentselsectiontemp));
				//if(checkvar > -1){
				if(tempsearch > -1){
					lastcreative = i;
					if(firstcreative == -1){
					firstcreative = i
					}
				}
			}
			
			}else{
				var tempsearch = allgallerycreatives[i][9].toLowerCase().search(currentselsection);
				if(tempsearch > -1){
					lastcreative = i;
					if(firstcreative == -1){
					firstcreative = i
					}
				}
			}
		}
		//alert(lastcreative);
		//alert(currentselcreative);
		//alert(firstcreative);
        if (currentplayselcreative == lastcreative){
				//End creative so hide right hand panel
					//document.getElementById("next").style.display = "none";
					//document.getElementById("next2").style.display = "none";
        }
		if(currentplayselcreative == firstcreative){
			//Start creative so hide left hand panel
					//document.getElementById("previous").style.display = "none";
					//document.getElementById("previous2").style.display = "none";
		}
	

	
	
	//Move up Control menu
	//moveupcontrol(0, 20);
	
	//Show Playlist

	
	
	
    //move in control menu
    //Ads to list if not innovation	
    if(playlistout==false){
    //moveup("controlmenu", 0, 50);
	
	}
    //hides menu if out
    if(menuout == true){
    //minimisemenu();
    }
    //sets iframe
    var iframevar = document.getElementById("iframecontent");
    frames['iframecontent'].location.href = allgallerycreatives[n][3];
    //iframevar.src = "http://innovation.doubleclick.net/" + allcreatives[m][n][3];;

    //currentcreative = n;
    

    //puts menu behind it
    
    //fades in iframe
    document.getElementById("pagecontent").style.zIndex = "250";
    opacity("pagecontent", 0,100,1);
	
	document.getElementById("welcome").style.zIndex = "201";
	document.getElementById("welcome").style.display = "none";
	
	currentplayselsection = "false";

}

function viewcreative(m, n){
    //Sets menu up if not the same
	gallerytype = false; //SETS TO INNOVATION GALLERY
	//Add to recent creatives
	if(previouslyviewedcreatives.length > 4){
	//remove 1 and keep replacing
		for(w=0;w<previouslyviewedcreatives.length-1;w++){
		previouslyviewedcreatives[w]=previouslyviewedcreatives[w+1];
		}
		previouslyviewedcreatives[w] = m + "|" + n;
	
	}else{ //Add on to end 
	previouslyviewedcreatives[previouslyviewedcreatives.length] = m + "|" + n;	
	
	}
	
	
    //move in control menu
    updateplaylist(m,n);
    if(playlistout==false){
    moveleft("controlmenu", 0, 50);}
    //hides menu if out
    if(menuout == true){
    //minimisemenu();
    }
    //sets iframe
    var iframevar = document.getElementById("iframecontent");
    frames['iframecontent'].location.href = "http://innovation.doubleclick.net/" + allcreatives[m][n][3];
    //iframevar.src = "http://innovation.doubleclick.net/" + allcreatives[m][n][3];;

    //currentcreative = n;
    
    if(customplaylist == false){
    //currentselsection = m;
	currentselcreative = n;
    }
    else{
	
		
    //currentselcreative=n;
    }
    //puts menu behind it
    document.getElementById("welcome").style.zIndex = 50;
    //fades in iframe
    document.getElementById("pagecontent").style.zIndex = "150";
    opacity("pagecontent", 0,100,200);

}



function moveleft(elem, amountmove, amount){
    playlistout = true;
	var currentcreative = document.getElementById(elem);
	clearInterval(currentcreative.interval);
	currentcreative.style.right = windowSize().width - (currentcreative.offsetLeft+currentcreative.offsetWidth) + 5 + "px";
	//alert(amountmove);
	//alert(windowSize().width - (currentcreative.offsetLeft+currentcreative.offsetWidth)) ;
	if((windowSize().width - (currentcreative.offsetLeft+currentcreative.offsetWidth))  < amountmove){
		//alert("hi");
		currentcreative.interval = setInterval("moveleft('" + elem + "', " + amountmove + ", " + amount + ")", amount);
	}

}


function moveright(elem, amountmove, amount){
    playlistout = false;
	var currentcreative = document.getElementById(elem);
	clearInterval(currentcreative.interval);
	//alert(currentcreative.offsetLeft);
	currentcreative.style.right = windowSize().width - (currentcreative.offsetLeft+currentcreative.offsetWidth) - 5 + "px";
	//alert(amountmove);
	//alert(windowSize().width - (currentcreative.offsetLeft+currentcreative.offsetWidth)) ;
	if((windowSize().width - (currentcreative.offsetLeft+currentcreative.offsetWidth))  > amountmove){
		//alert("hi");
		//alert(currentcreative.offsetLeft);
		currentcreative.interval = setInterval("moveright('" + elem + "', " + amountmove + ", " + amount + ")", amount);
	}

}




function gotoNext(){
    if(customplaylist == true){
	currentlylookingatplaylist++;
		currentplayselcreative++;
		currentlylookingat++;
		if(currentlylookingatplaylist == playlistcreatives.length){
		currentplayselcreative=0;
		currentlylookingat=0;
		currentlylookingatplaylist = 0;
		}
		viewmenucreative(currentlylookingatplaylist, currentlylookingatplaylist);
      //  if(currentselcreative < playlistcreatives.length-1){
        //    viewgallerycreative(playlistcreatives[currentselcreative+1]);
       // }
		//else{
			//Go to 1?
			
		
		//}
    }
    else{
	
		//TO WRITE
		
		//Find Section
		var foundresult = "";
		var checkfound = "false";
		//var nextfound = "false"; //Var to check if theres another creative
		
		//Find out if last one!?!?
		var searchstring = "";
		if(currentselsection.search("searchfor") == 0){
		//Search Term
		searchstring = currentselsection.substring(9, currentselsection.length);
		} else if(currentselsection.search("inno") == 0){
		//Spotlight Playlist
		searchstring = currentselsection.substring(4, currentselsection.length);
		} else {
		//Section Playlist
		searchstring = currentselsection;
		}
		var totalamount = 0;
		
		for(i=currentselcreative+1; i<allgallerycreatives.length; i++){
			var tempsearch = currentselsection.search("inno");
			if(tempsearch == 0){
			//Inno Creative
			if(allgallerycreatives[i][12] == 1){
				var tempsearch = (allgallerycreatives[i][15].toLowerCase().search(gotid2));
				if(tempsearch > -1){
					totalamount++;
				}
			}
			
			}else{
				var tempsearch = (allgallerycreatives[i][7].toLowerCase()+","+allgallerycreatives[i][2].toLowerCase()+","+allgallerycreatives[i][1].toLowerCase()+","+allgallerycreatives[i][0].toLowerCase()+","+allgallerycreatives[i][9].toLowerCase()+","+allgallerycreatives[i][8].toLowerCase()+","+allgallerycreatives[i][13].toLowerCase()+","+allgallerycreatives[i][5].toLowerCase()).search(searchstring);
				if(tempsearch > -1){
					totalamount++;
				}
			}
		}
		
		var tempvar = 1;
		if(totalamount > 0){
		tempvar = currentselcreative+1
		}
				
		for(i=tempvar; i<allgallerycreatives.length; i++){
		//search for inno
		//alert("hi");
			if(checkfound == "false"){
			var tempsearch = currentselsection.search("inno");
			if(tempsearch == 0){
			//Inno Creative
				if(allgallerycreatives[i][12] == 1){
				currentselsectiontemp = currentselsection.substring(4, currentselsection.length);
							//	var tempsearch = (allgallerycreatives[i][9].toLowerCase()+","+allgallerycreatives[i][8].toLowerCase()+","+allgallerycreatives[i][13].toLowerCase()+","+allgallerycreatives[i][5].toLowerCase()).search(currentselsectiontemp);
							var tempsearch = (allgallerycreatives[i][15].toLowerCase().search(currentselsectiontemp));
				if(tempsearch > -1){
					checkfound = "true";
					foundresult = i;
				}
			}
			
			}else{
					var tempsearch = (allgallerycreatives[i][7].toLowerCase()+","+allgallerycreatives[i][2].toLowerCase()+","+allgallerycreatives[i][1].toLowerCase()+","+allgallerycreatives[i][0].toLowerCase()+","+allgallerycreatives[i][9].toLowerCase()+","+allgallerycreatives[i][8].toLowerCase()+","+allgallerycreatives[i][13].toLowerCase()+","+allgallerycreatives[i][5].toLowerCase()).search(searchstring);
				if(tempsearch > -1){
					checkfound = "true";
					foundresult = i;
				}
			}
			}
		}
		
		
		if(checkfound == "true"){
			if(document.getElementById("playlistcontainer").offsetLeft == "0"){ //Out
            viewgallerycreative(foundresult);
			}else{
				viewgallerycreative(foundresult);
				moveleftplaylist()
			}
		}
    }
	
	pageTracker._trackPageview("Pressed Next Creative");
}

function gotoPrevious(){
//newfocus(currentselcreative-1);
    if(customplaylist == true){
        //if(currentselcreative < 0){
            //currentselcreative--;
			currentlylookingatplaylist--;
			currentplayselcreative--;
			currentlylookingat--;
			if(currentlylookingatplaylist == -1){
			currentplayselcreative=playlistcreatives.length-1;
			currentlylookingat=playlistcreatives.length-1;
			currentlylookingatplaylist = playlistcreatives.length-1;
			}
			//var arrplaylist = playlistcreatives[currentselcreative].split( "|" );
            viewmenucreative(currentlylookingatplaylist, currentlylookingatplaylist);

       // }
    }
    else{
	
		var foundresult = "";
		var checkfound = "false";
		//var nextfound = "false"; //Var to check if theres another creative
		var searchstring = "";
		if(currentselsection.search("searchfor") == 0){
		//Search Term
		searchstring = currentselsection.substring(9, currentselsection.length);
		} else if(currentselsection.search("inno") == 0){
		//Spotlight Playlist
		searchstring = currentselsection.substring(4, currentselsection.length);
		} else {
		//Section Playlist
		searchstring = currentselsection;
		}
		
		var totalamount = 0;
		
		for(i=currentselcreative-1; i>0; i--){
			var tempsearch = currentselsection.search("inno");
			  if(tempsearch == 0){
				if(allgallerycreatives[i][12] == 1){
				//var tempsearch = (allgallerycreatives[i][9].toLowerCase()+","+allgallerycreatives[i][8].toLowerCase()+","+allgallerycreatives[i][13].toLowerCase()+","+allgallerycreatives[i][5].toLowerCase()).search(searchstring);
				var tempsearch = (allgallerycreatives[i][15].toLowerCase().search(searchstring));
				if(tempsearch > -1){
			//Inno Creative
				//Add creative to list
					totalamount++;
			  }
			}
		}else{
				var tempsearch = (allgallerycreatives[i][7].toLowerCase()+","+allgallerycreatives[i][2].toLowerCase()+","+allgallerycreatives[i][1].toLowerCase()+","+allgallerycreatives[i][0].toLowerCase()+","+allgallerycreatives[i][9].toLowerCase()+","+allgallerycreatives[i][8].toLowerCase()+","+allgallerycreatives[i][13].toLowerCase()+","+allgallerycreatives[i][5].toLowerCase()).search(searchstring);
				if(tempsearch > -1){
					totalamount++;
				}
			}
		}
		
		var tempvar = allgallerycreatives.length-1;
		if(totalamount > 0){
		//alert(totalamount);
		tempvar = currentselcreative-1;
		}
		for(i=tempvar; i>0; i--){
		//search for inno
		//alert("hi");
			if(checkfound == "false"){
			var tempsearch = currentselsection.search("inno");
			if(tempsearch == 0){
			//Inno Creative
				if(allgallerycreatives[i][12] == 1){
				//var tempsearch = (allgallerycreatives[i][9].toLowerCase()+","+allgallerycreatives[i][8].toLowerCase()+","+allgallerycreatives[i][13].toLowerCase()+","+allgallerycreatives[i][5].toLowerCase()).search(searchstring);
				var tempsearch = (allgallerycreatives[i][15].toLowerCase().search(searchstring));
			
				if(tempsearch > -1){
				//Add creative to list
					foundresult = i;
					checkfound = "true";
				}
				}
			
			}else{
				var tempsearch = (allgallerycreatives[i][7].toLowerCase()+","+allgallerycreatives[i][2].toLowerCase()+","+allgallerycreatives[i][1].toLowerCase()+","+allgallerycreatives[i][0].toLowerCase()+","+allgallerycreatives[i][9].toLowerCase()+","+allgallerycreatives[i][8].toLowerCase()+","+allgallerycreatives[i][13].toLowerCase()+","+allgallerycreatives[i][5].toLowerCase()).search(searchstring);
				if(tempsearch > -1){
					checkfound = "true";
					foundresult = i;
				}
			}
			}
		}	
			if(checkfound == "true"){
				//alert(foundresult);
            if(document.getElementById("playlistcontainer").offsetLeft == "0"){ //Out
            viewgallerycreative(foundresult);
			}else{
				viewgallerycreative(foundresult);
				moveleftplaylist()
			}
			}
		
		
		
		
    }
	pageTracker._trackPageview("Pressed Previous Creative");
}




function moveup(elem, amountmove, amount){
	var currentcreative = document.getElementById(elem);
	clearInterval(currentcreative.interval);
	currentcreative.style.top = currentcreative.offsetTop - 10 + "px";
	if(currentcreative.offsetTop > amountmove){
		currentcreative.interval = setInterval("moveup('" + elem + "', " + amountmove + ", " + amount + ")", amount);
	}

}

function movedowncontrol(amountmove, amount){
	var currentcreative = document.getElementById("control");
	clearInterval(currentcreative.interval);
	currentcreative.style.bottom = (-currentcreative.offsetHeight)+5;
	/*
	currentcreative.style.bottom = (windowSize().height - (currentcreative.offsetTop+currentcreative.offsetHeight))-1 +"px";
	if((windowSize().height - (currentcreative.offsetTop+currentcreative.offsetHeight)-5) > amountmove){
		currentcreative.interval = setInterval("movedowncontrol(" + amountmove + ", " + amount + ")", amount);
	}
	else{
	//set move up there
		var currentcreative2 = document.getElementById("controlheader");
		currentcreative2.innerHTML = '<a href="javascript:moveupcontrol(0, 10)">Control Panel</a>';
	}*/

}

function moveupcontrol(amountmove, amount){
	var currentcreative = document.getElementById("control");
	clearInterval(currentcreative.interval);

currentcreative.style.bottom = 0;

	//alert(amountmove);
	//alert(windowSize().height - (currentcreative.offsetTop+currentcreative.offsetHeight));
	/*if((windowSize().height - (currentcreative.offsetTop+currentcreative.offsetHeight)) < amountmove){
		currentcreative.style.bottom = (windowSize().height - (currentcreative.offsetTop+currentcreative.offsetHeight))+ 1 +"px";
		currentcreative.interval = setInterval("moveupcontrol(" + amountmove + ", " + amount + ")", amount);
	}
	else{
	//set move up there
	var currentcreative2 = document.getElementById("controlheader");
	currentcreative2.innerHTML = "";
	//var vardiv1 = document.createElement("div");
	//vardiv1.setAttribute("id", "ControlPanelDiv");
	var vara1 = document.createElement("a");
	vara1.setAttribute("href", "javascript:movedowncontrol(-35, 10)");
	vara1.appendChild(document.createTextNode("Control Panel"));
	currentcreative2.appendChild(vara1);
	//currentcreative2.appendChild(vardiv1); 
		//Old
		//urrentcreative2.innerHTML = "<a href='javascript:movedowncontrol(-35, 10)'>Control Panel</a>";
	}*/

}



function showplaylist(){

	//clearTimeout(newvariable);	
	document.getElementById("control2").style.display = "block";	
	document.getElementById("playlist").style.display = "block";
	document.getElementById("playlistheader").style.display = "block";
	document.getElementById("playlistcontainer").style.display = "block";
	var currentelem = document.getElementById("playlistcontainer");
	
	var currenttop = 0;
	if(document.getElementById("menucontainer").offsetTop < -20){
	currenttop = 0;
	}
	currentelem.style.top =  currenttop + "px";
	moverightplaylist()
	/*
	if(BrowserDetect.browser == "MSIE"|BrowserDetect.browser == "Explorer"){
	currentelem.style.top =  currenttop + "px";
		var minivar = document.getElementById("showplaylisticon");
		var avar = document.getElementById("playlistaref");
		avar.href = "javascript:hideplaylist()";
	}else{	
	currentelem.style.top = currentelem.offsetTop - 10 + "px";
	if(currentelem.offsetTop > currenttop){	
		//alert('hi');
		var newvariable = setTimeout("showplaylist('var')", 10);
	}else{
		currentelem.style.top =  currenttop + "px";
		var minivar = document.getElementById("showplaylisticon");
		var avar = document.getElementById("playlistaref");
		avar.href = "javascript:hideplaylist()";
	}
	currentelem = "";
	}*/
	setplaylistheight();
	
}
function hideplaylist(){
	document.getElementById("control2").style.display = "none";	
	document.getElementById("playlist").style.display = "none";
	document.getElementById("playlistheader").style.display = "none";
	document.getElementById("playlistcontainer").style.display = "none";
	var currentelem = document.getElementById("playlistcontainer");
	clearInterval(currentelem.interval);
	currentelem.style.top =  windowSize().height+2;
	moveleftplaylist();
	//alert(BrowserDetect.browser);
	/*if(BrowserDetect.browser == "MSIE"|BrowserDetect.browser == "Explorer"){
		currentelem.style.top = windowSize().height + 10;
		var minivar = document.getElementById("showplaylisticon");
		//minivar.setAttribute("onclick", "showplaylist()");
		//minivar.onclick = function() {showplaylist()};
		var avar = document.getElementById("playlistaref");
		avar.href = "javascript:showplaylist()";
	}
	else{
	currentelem.style.top = (currentelem.offsetTop) + 10 + "px";
	
	if(currentelem.offsetTop < windowSize().height){
		currentelem.interval = setInterval("hideplaylist()", 2); 
	}
	else{
		var minivar = document.getElementById("showplaylisticon");
		//minivar.setAttribute("onclick", "showplaylist()");
		//minivar.onclick = function() {showplaylist()};
		var avar = document.getElementById("playlistaref");
		avar.href = "javascript:showplaylist()";
	}
	}*/
}




//FUNCTIONS TO WRITE

function search(searchtype){
if(searchtype=="new"){
var searchstring = document.searchform2.newsearchtext.value.toLowerCase();
}
else{
	var searchstring = document.searchform.searchtext.value.toLowerCase();
	}
	var foundresults = false;
	
        var welcomemain = document.getElementById("welcomemain");
		 var welcome = document.getElementById("welcome");
        welcomemain.innerHTML = ""; //Clears previous results
		welcome.style.display = "block";
		welcome.style.zIndex = 260;
		resizewelcomecheck();
		
		currentselsection = "searchfor"+searchstring;
		currentelem2 = document.getElementById("welcometitletext");
            
				if(searchinside== "innoall"){ //Show all innovation gallery ones
					   //currentselsection = -1;
					   //alert("3");
                        currentelem2 = document.getElementById("welcometitletext");
						currentelem2.innerHTML = "Searching in All Creatives";
						//

						for(n=0;n<allgallerycreatives.length-1;n++){
						
								var checkvar = (allgallerycreatives[n][7].toLowerCase()+","+allgallerycreatives[n][2].toLowerCase()+","+allgallerycreatives[n][1].toLowerCase()+","+allgallerycreatives[n][0].toLowerCase()+","+allgallerycreatives[n][9].toLowerCase()+","+allgallerycreatives[n][8].toLowerCase()+","+allgallerycreatives[n][13].toLowerCase()+","+allgallerycreatives[n][5].toLowerCase()).search(searchstring);
								if(checkvar > -1){
								generategallerycreative('creativemain'+n, n, 'welcomemain');
								foundresults = true;
								}
							
							//}

						}
						
					}else{
					
					
					//currentelem2 = document.getElementById("welcometitletext");
					//Find Title;
					var title;
					for(n=0; n < allgallerycreativessections.length;n++){
						for(m=0; m < allgallerycreativessections[n].length;m++){
							if(allgallerycreativessections[n][m][0]==searchinside){
								
								title = allgallerycreativessections[n][m][1];
								currentelem2.innerHTML = "Searching results inside " + title;
							}
						}
					}
						//alert(2);
					
					//Check if Innovation Link:
					if(searchinside.search("inno") == 0){
					//Check 10th element
					//alert("in inno");
						for(n=0; n < allgallerycreatives.length;n++){
							var checkvar = allgallerycreatives[n][10];
							//alert(checkvar);
							//alert(currentselsection);
							
							if(checkvar == searchinside){
								var checkvar2 = (allgallerycreatives[n][7].toLowerCase()+","+allgallerycreatives[n][2].toLowerCase()+","+allgallerycreatives[n][1].toLowerCase()+","+allgallerycreatives[n][0].toLowerCase()+","+allgallerycreatives[n][9].toLowerCase()+","+allgallerycreatives[n][8].toLowerCase()+","+allgallerycreatives[n][13].toLowerCase()+","+allgallerycreatives[n][5].toLowerCase()).search(searchstring);
								if(checkvar2 > -1){
										generategallerycreative('creativemain'+n, n, 'welcomemain');
                            			foundresults = true;
								}
							}
						}
					
					}
					else{ //Check normal tags
					
						for(n=0; n < allgallerycreatives.length;n++){
							var checkvar = (allgallerycreatives[n][7].toLowerCase()+","+allgallerycreatives[n][2].toLowerCase()+","+allgallerycreatives[n][1].toLowerCase()+","+allgallerycreatives[n][0].toLowerCase()+","+allgallerycreatives[n][9].toLowerCase()+","+allgallerycreatives[n][8].toLowerCase()+","+allgallerycreatives[n][13].toLowerCase()+","+allgallerycreatives[n][5].toLowerCase()).search(searchinside);
								if(checkvar > -1){
									var checkvar2 = (allgallerycreatives[n][7].toLowerCase()+","+allgallerycreatives[n][2].toLowerCase()+","+allgallerycreatives[n][1].toLowerCase()+","+allgallerycreatives[n][0].toLowerCase()+","+allgallerycreatives[n][9].toLowerCase()+","+allgallerycreatives[n][8].toLowerCase()+","+allgallerycreatives[n][13].toLowerCase()+","+allgallerycreatives[n][5].toLowerCase()).search(searchstring);
									if(checkvar2 > -1){
                            		generategallerycreative('creativemain'+n, n, 'welcomemain');
                            		foundresults = true;
									}
							}
						}
					}
	
		}
		
        
     if(foundresults == false){ //Gives output if nothing found
        welcomemain.innerHTML="No matching creatives found";
     }
    
}





function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();


var dragObj = new Object();
dragObj.zIndex = 0;

        function getabY( oElement )
        {
            var iReturnValue = 0;
        while( oElement != null ) {
        //alert("hi");
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
        }
        return iReturnValue;
        }
        
        function getabX( oElement )
        {
            var iReturnValue = 0;
        while( oElement != null ) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
        }
        return iReturnValue;
        }




function generatecreative(id, m, n, place){

							var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', id);
							newdiv.setAttribute('class', "creativeclass");
							newdiv.className = "creativeclass";
							//newdiv.setAttribute('onclick', 'viewcreative(' + m + ',' + n + ')');
                            //newdiv.setAttribute('onmousedown', 'drag("creativemain'+n+'", event)');
							//newdiv.setAttribute('onclick', 'showcreative("creative' + i + '")');
							//newdiv.setAttribute('onmousedown', 'dragStart(event, "creativemain'+n+'")');
							//newdiv.setAttribute('onmousedown', 'drag(event, "creativemain'+n+'")');
							var putplace = document.getElementById(place);
							putplace.appendChild(newdiv);
							
							//if(customplaylist == true){
							var newdiv2 = document.createElement('div');
  							newdiv2.setAttribute('id', 'addbtnmain'+n);
							newdiv2.setAttribute('class', 'addbtnicon');
							newdiv2.className = 'addbtnicon';
							//newdiv2.setAttribute('onclick', 'addcreative(' + m + ',' + n + ')');
							//newdiv2.onclick = function() {addcreative(m,n)};
							newdiv2.innerHTML="<a href='javascript:addcreative("+m+","+n+")'><img src='galleryicons/plus.png'></a>";
							newdiv.appendChild(newdiv2);
							//}

							var newdiv2 = document.createElement('div');
							newdiv2.setAttribute('id', 'creativeclassimage'+id);
							newdiv2.setAttribute('class', 'creativeclassimage');
							newdiv2.className = 'creativeclassimage';
							newdiv.appendChild(newdiv2);
							newdiv2.setAttribute('onclick', 'viewcreative(' + m + ',' + n + ')');
							newdiv2.onclick = function() {viewcreative(m,n)};

							var newimg = document.createElement('img');
							newimg.setAttribute('src', allcreatives[m][n][4]);
							newdiv2.appendChild(newimg);

							var newdiv2 = document.createElement('div');
							newdiv2.setAttribute('id', 'creativeclassinfo');
							newdiv2.setAttribute('class', 'creativeclassinfo');
							newdiv2.className = 'creativeclassinfo';
							newdiv.appendChild(newdiv2);
							newdiv2.setAttribute('onclick', 'viewcreative(' + m + ',' + n + ')');
							newdiv2.onclick = function() {viewcreative(m,n)};

							var newdiv3 = document.createElement('div');
							newdiv3.setAttribute('class', 'creativeclasstitle');
							newdiv3.className = 'creativeclasstitle';
							newdiv3.innerHTML = "<a href='javascript:viewcreative("+m+","+n+")'>"+allcreatives[m][n][0]+"</a>";
							newdiv2.appendChild(newdiv3);

							var newdiv3 = document.createElement('div');
							newdiv3.setAttribute('class', 'creativeclasscreativeagency');
							newdiv3.className = 'creativeclasscreativeagency';
							//newdiv3.innerHTML = allcreatives[m][n][2];
							newdiv3.innerHTML = "<a href='javascript:viewcreative("+m+","+n+")'>"+allcreatives[m][n][2]+"</a>";
							newdiv2.appendChild(newdiv3);

}


/*function testfunc(elem){

var fake = document.getElementById(elem);
fake.style.display = "none";
alert('hi');
} */

function viewsectioncreative(n){
currentplayselsection = "true";
viewgallerycreative(n);
}

function generategallerycreative(id, n, place, custom){


							

							var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', id);
							newdiv.setAttribute('class', "creativeclass");
							newdiv.className = "creativeclass";
							
							//Do YT Search
							//var ytsearch = allgallerycreatives[n][6]+allgallerycreatives[n][9].toLowerCase().search("youtube");
							var checkvar = (((allgallerycreatives[n][9]+","+allgallerycreatives[n][6]).toLowerCase())).search("youtube");
							if(checkvar > -1){
								newdiv.className = "ytcreativeclass";
							}
							
							
							var putplace = document.getElementById(place);
							putplace.appendChild(newdiv);

							
							var newdiv2 = document.createElement('div');
  							newdiv2.setAttribute('id', 'addbtnmain'+n);
							newdiv2.setAttribute('class', 'addbtnicon');
							newdiv2.className = 'addbtnicon';
							
							
							if(place != "playlist"){
							var vardiv1 = document.createElement("div");
							vardiv1.setAttribute("id", "selectedplaylisttitle"+n);
							vardiv1.setAttribute("class", "addbtnicon");
							vardiv1.className = "addbtnicon";
							var vara1 = document.createElement("a");
							vara1.setAttribute("href", "javascript:addgallerycreative("+n+")");
							varimg1 = document.createElement("img");
							varimg1.className = 'miniicon';
							varimg1.setAttribute("src", "galleryicons/pluscreative.gif");
							var checkvar = (((allgallerycreatives[n][9]+","+allgallerycreatives[n][6]).toLowerCase())).search("youtube");
							if(checkvar > -1){
								varimg1.setAttribute("src", "galleryicons/plus_yt.gif");
							}
							vara1.appendChild(varimg1);
							vardiv1.appendChild(vara1);
							newdiv.appendChild(vardiv1); 
							vardiv1.style.display = "block";}else{	
							if(customplaylist == false){						
							var vardiv1 = document.createElement("div");
							vardiv1.setAttribute("id", "selectedplaylisttitle"+n);
							vardiv1.setAttribute("class", "addbtnicon");
							vardiv1.className = "addbtnicon";
							var vara1 = document.createElement("a");
							vara1.setAttribute("href", "javascript:addgallerymenucreative("+n+")");
							varimg1 = document.createElement("img");
							varimg1.className = 'miniicon';
							varimg1.setAttribute("src", "galleryicons/pluscreative.gif");
							var checkvar = (((allgallerycreatives[n][9]+","+allgallerycreatives[n][6]).toLowerCase())).search("youtube");
							if(checkvar > -1){
								varimg1.setAttribute("src", "galleryicons/plus_yt.gif");
							}
							vara1.appendChild(varimg1);
							vardiv1.appendChild(vara1);
							newdiv.appendChild(vardiv1); 
							vardiv1.style.display = "block";
							} else{
							var vardiv1 = document.createElement("div");
							vardiv1.setAttribute("id", "selectedplaylisttitle"+n);
							vardiv1.setAttribute("class", "addbtnicon");
							vardiv1.className = "addbtnicon";
							var vara1 = document.createElement("a");
							vara1.setAttribute("href", "javascript:addgallerycreative("+n+")");
							varimg1 = document.createElement("img");
							varimg1.className = 'miniicon';
							varimg1.setAttribute("src", "galleryicons/plus_grey.gif");
							vara1.appendChild(varimg1);
							vardiv1.appendChild(vara1);
							newdiv.appendChild(vardiv1); 
							vardiv1.style.display = "block";
							}
							}
							
							//Email icon
							var newdiv2 = document.createElement('div');
  							newdiv2.setAttribute('id', 'emailbtnmain'+n);
							newdiv2.setAttribute('class', 'emailbtnicon');
							newdiv2.className = 'emailbtnicon';
							newdiv2.id = 'emailbtnmain'+n;
							newdiv2.innerHTML = "<a href='javascript:emailcreative("+n+")'><img src='galleryicons/mailcreative.jpg' class='miniicon'></a>";
							newdiv.appendChild(newdiv2);
							
							
							//Info Icon
							var newdiv2 = document.createElement('div');
  							newdiv2.setAttribute('id', 'infobtnmain'+n);
							newdiv2.setAttribute('class', 'infobtnicon');
							newdiv2.className = 'infobtnicon';
							newdiv2.innerHTML = "<a href='javascript:showcreativeinfo("+n+")'><img src='galleryicons/infocreative.gif' class='miniicon'></a>";
							
							var checkvar = (((allgallerycreatives[n][9]+","+allgallerycreatives[n][6]).toLowerCase())).search("youtube");
							if(checkvar > -1){
								newdiv2.innerHTML = "<a href='javascript:showcreativeinfo("+n+")'><img src='galleryicons/info_yt.gif' class='miniicon'></a>";
							}
							newdiv.appendChild(newdiv2);

							var newdiv2 = document.createElement('div');
							newdiv2.setAttribute('id', 'creativeclassimage'+id);
							newdiv2.setAttribute('class', 'creativeclassimage');
							newdiv2.className = 'creativeclassimage';
							newdiv.appendChild(newdiv2);
							
							//alert(place);
							//if(place.id != "playlist"){
							//alert(custom);
							if(custom != "undefined"){
							//alert(custom)
							newdiv2.setAttribute('onclick', 'viewgallerycreative(' + n + ')');
							newdiv2.onclick = function() {viewgallerycreative(n)};
							}else{
							newdiv2.setAttribute('onclick', 'viewgallerycreative('+n+',' + custom + ')');
							newdiv2.onclick = function() {viewgallerycreative(custom)};
							newdiv2.myflag = n;
							}
							//}else{
							//newdiv2.setAttribute('onclick', 'viewsectioncreative(' + n + ')');
							//newdiv2.onclick = function() {viewsectioncreative(n)};
							//}

							var newimg = document.createElement('img');
							newimg.setAttribute('src', allgallerycreatives[n][4]);
							newimg.style.width = "75px";
							newimg.style.height = "60px";
							newdiv2.appendChild(newimg);

							var newdiv2 = document.createElement('div');
							newdiv2.setAttribute('id', 'creativeclassinfo');
							newdiv2.setAttribute('class', 'creativeclassinfo');
							newdiv2.className = 'creativeclassinfo';
							newdiv.appendChild(newdiv2);
							//newdiv2.setAttribute('onclick', 'viewgallerycreative(' + n + ')');
							//newdiv2.onclick = function() {viewgallerycreative(n)};
							
							if(custom != "undefined"){
							newdiv2.setAttribute('onclick', 'viewgallerycreative(' + n + ')');
							newdiv2.onclick = function() {viewgallerycreative(n)};
							}else{
							newdiv2.setAttribute('onclick', 'viewgallerycreative('+n+',' + custom + ')');
							newdiv2.onclick = function() {viewgallerycreative(custom)};
							newdiv2.myflag = n;
							}

							var newdiv3 = document.createElement('div');
							newdiv3.setAttribute('class', 'creativeclasstitle');
							newdiv3.className = 'creativeclasstitles';
							
							
							//newdiv3.innerHTML = "<a href='javascript:viewgallerycreative("+n+")'>"+allgallerycreatives[n][7]+"</a>";
							var tempcreative = allgallerycreatives[n][7];
							if(tempcreative.length > 13){
								
							newdiv3.setAttribute("onmouseover", "Tip('"+allgallerycreatives[n][7]+"',BGCOLOR,'#FFFFE1')");
							newdiv3.onmouseover = function() {Tip(allgallerycreatives[n][7],BGCOLOR,'#FFFFE1')};
							newdiv3.onmouseout = function(){UnTip()};
							newdiv3.setAttribute("onmouseout", "UnTip()");
							tempcreative = tempcreative.substring(0, 11)+ "...";
							}
							var checkvar = (((allgallerycreatives[n][9]+","+allgallerycreatives[n][6]).toLowerCase())).search("youtube");
							if(checkvar > -1){
								newdiv3.className = 'ytcreativeclasstitles';
							}
							
							newdiv3.innerHTML = tempcreative;
							
							
							newdiv2.appendChild(newdiv3);
							
							if(custom != "undefined"){
							newdiv2.setAttribute('onclick', 'viewgallerycreative(' + n + ')');
							newdiv2.onclick = function() {viewgallerycreative(n)};
							}else{
							newdiv2.setAttribute('onclick', 'viewgallerycreative('+n+',' + custom + ')');
							newdiv2.onclick = function() {viewgallerycreative(custom)};
							newdiv2.myflag = n;
							}

							var newdiv3 = document.createElement('div');
							newdiv3.setAttribute('class', 'creativeclasscreativeagency');
							newdiv3.className = 'creativeclasscreativeagency';
							var tempcreative = allgallerycreatives[n][0];
							if(tempcreative.length > 15){
							tempcreative = tempcreative.substring(0, 13)+ "...";
							newdiv3.setAttribute("onmouseover", "Tip('"+allgallerycreatives[n][0]+"',BGCOLOR,'#FFFFE1')");
							newdiv3.onmouseover = function() {Tip(allgallerycreatives[n][0],BGCOLOR,'#FFFFE1')};
							newdiv3.onmouseout = function(){UnTip()};
							newdiv3.setAttribute("onmouseout", "UnTip()");
							
							}
							//newdiv3.innerHTML = "<a href='javascript:viewgallerycreative("+n+")'>"+tempcreative+"</a>";
							newdiv3.innerHTML = tempcreative;
							newdiv2.appendChild(newdiv3);
							
							


}





var addedbefore=false;

function customplaylistfn(){
    if(customplaylist == true){ //Already a custom playlist enabled
//lightbox asking user if wants to wipe

    }
    else{
    //clear old playlist outnewdiv3.innerHTML = "<a href='javascript:viewgallerycreative("+n+")'>"+allgallerycreatives[n][0]+"</a>";
     var playlistdiv = document.getElementById("playlist");
	 var playlisttitlediv = document.getElementById("playlisttitlediv");
	 playlisttitlediv.innerHTML = "<div id='playlisttitle' onclick='playlisttosection()'><a href='javascript:playlisttosection()'>Section Playlist</a></div><div id='playlisttitle' onclick='playlisttorecent()'><a href='javascript:playlisttorecent()'>History Playlist</a></div><div id='selectedplaylisttitle' onclick='hideplaylist()'><a href='javascript:hideplaylist()'>Custom Playlist</a></div>";
     //Sets playlist to true
     customplaylist = true;
     
     //Makes sure window isn't up
     document.getElementById("welcome").style.display="none";
     
                            var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', "addcreativespeal");
							newdiv.setAttribute('class', 'creativeclass');
							newdiv.className = 'creativeclass';
							newdiv.style.left = "2px";
							newdiv.style.top="50px";
							newdiv.style.width = "140px";
							newdiv.style.height = "70px";
							newdiv.innerHTML = "To add creatives to this playlist please select the '+' symbol next to each creative.";
							playlistdiv.appendChild(newdiv);
							
							var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', "removecreativespeal");
							newdiv.setAttribute('class', 'creativeclass');
							newdiv.className = 'creativeclass';
							newdiv.style.left = "2px";
							newdiv.style.top="50px";
							newdiv.style.width = "140px";
							newdiv.style.height = "70px";
							newdiv.innerHTML = "To remove creatives in this playlist please select the '-' symbol next to each creative.";
							playlistdiv.appendChild(newdiv);
							
							var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', "removecreativespeal");
							newdiv.setAttribute('class', 'creativeclass');
							newdiv.className = 'creativeclass';
							newdiv.style.left = "2px";
							newdiv.style.top="50px";
							newdiv.style.width = "140px";
							newdiv.style.height = "70px";
							newdiv.innerHTML = "To move creatives in this playlist please select the '<' & '>' symbols on each creative.";
							playlistdiv.appendChild(newdiv);
     
     
     
     }

}

function addcreative(m, n){
//alert(customplaylist);
	if(addedbefore==false){
	//var playlistdiv = document.getElementById("playlist");
	//playlistdiv.innerHTML = "<div id='playlisttitle'  onclick='hideplaylist()'>Custom Playlist</div>";
		if(customplaylist == false){
		//Put up a lightBox
		var settinghtml='<div id="title" class="white_content_title">Custom Playlists<div id="closebtn" onclick="closelightbox()"><img src="galleryicons/close26.gif"></a></div></div><div id= class="settingstype">It appears you have not added a creative to the custom playlist, please read the info in the Custom Playlist menu for more details</div>';
createlightbox(settinghtml, 150, 150);
		
		}
	}
	addedbefore=true;
	customplaylist = true;
        //Add to database
        playlistcreatives[playlistcreatives.length] = m + "|" + n;
        //Add to visual playlist
        generatecreative("menuiconcustom"+playlistcreatives.length, m, n, "playlist");
        //Add Remove button
		updateplaylist();
		/* OLDD ADD
		var generatedcreative = document.getElementById("creativeclassimagemenuiconcustom"+playlistcreatives.length);
		generatedcreative.onclick = function(){ clickoncustomplaylist(m,n, playlistcreatives.length) };
		//generatedcreative.creativeclassinfo.onclick = function(){ clickoncustomplaylist(m,n, playlistcreatives.length) };
        					var currentmenuitem = document.getElementById("menuiconcustom"+playlistcreatives.length);
                            var newdiv2 = document.createElement('div');
  							newdiv2.setAttribute('id', 'removebtnmain'+n);
							newdiv2.setAttribute('class', 'removebtnicon');
							newdiv2.className = 'removebtnicon';
							newdiv2.onclick = function(){removecreative(playlistcreatives.length)};
							newdiv2.innerHTML="-";
							currentmenuitem.appendChild(newdiv2);
							var newdiv2 = document.createElement('div');
  							newdiv2.setAttribute('id', 'moveupbtnmain'+n);
							newdiv2.setAttribute('class', 'moveupbtnicon');
							newdiv2.className = 'moveupbtnicon';
							newdiv2.onclick = function(){moveupcreative(playlistcreatives.length)};
							newdiv2.innerHTML="^";
							currentmenuitem.appendChild(newdiv2);
							var newdiv2 = document.createElement('div');
  							newdiv2.setAttribute('id', 'movedownbtnmain'+n);
							newdiv2.setAttribute('class', 'movedownbtnicon');
							newdiv2.className = 'movedownbtnicon';
							newdiv2.onclick = function(){movedowncreative(playlistcreatives.length)};
							newdiv2.innerHTML="v";
							currentmenuitem.appendChild(newdiv2); */

}

function addgallerycreative(n){
	if(customplaylist == false){
	addedbefore=true;
	if(addedbefore==false){
	//var playlistdiv = document.getElementById("playlist");
	//playlistdiv.innerHTML = "<div id='playlisttitle'  onclick='hideplaylist()'>Custom Playlist</div>";
		
		//Put up a lightBox
		//var settinghtml='<div id="title" class="white_content_title">Custom Playlists<div id="closebtn" onclick="closelightbox()"><a 		href="javascript:closelightbox()">CLOSE</a></div></div><div id= class="settingstype">It appears you have not added a creative to the custom playlist, please read the info in the Custom Playlist menu for more details</div>';
//createlightbox(settinghtml, 150, 150);
			//display 
		if(playlistout==false){
    		moveleft("playlistcontainer", 0, 50);}
			customplaylist = true;
			previousplaylist = false;
			updateplaylist();
			addedbefore = true;
		
		}
		else{
			addedbefore=true;
			customplaylist = true;
        //Add to database
        playlistcreatives[playlistcreatives.length] = n;
        //Add to visual playlist
        generategallerycreative("menuiconcustom"+playlistcreatives.length, n, "playlist");
        //Add Remove button
		updateplaylist();
		showplaylist();
		
		
		
		}
	}else{
	
	
	
		//addedbefore=true;
		customplaylist = true;
        //Add to database
        playlistcreatives[playlistcreatives.length] = n;
        //Add to visual playlist
        //generategallerycreative("menuiconcustom"+playlistcreatives.length, n, "playlist");
        //Add Remove button
		updateplaylist();
		
		}
		showplaylist();
}

function addgallerymenucreative(n){
//Add to list
playlistcreatives[playlistcreatives.length] = n;
//Show Response to user
		var newdiv2 = document.createElement('div');
		newdiv2.className = "useraddedcreative";
		newdiv2.id = "useraddedcreative";
		newdiv2.setAttribute("id", "useraddedcreative");
		newdiv2.innerHTML = "Creative Added";
		document.getElementById("playlistheader").appendChild(newdiv2);
		window.setTimeout(removeuseraddedcreative,1000);

		
//Hide Response to user
}

function removeuseraddedcreative(){
//document.getElementById("useraddedcreative").style.display = "none";
document.getElementById("playlistheader").removeChild(document.getElementById("useraddedcreative"));
}

function moveupcreative(eid){

	if(doingmoving == false){
	
	doingmoving = true;
	if(eid == currentlylookingatplaylist){
	currentlylookingatplaylist--;
	//alert('hi');
	} else if(currentlylookingatplaylist == eid-1){
	currentlylookingatplaylist++;
	//alert('hi2');
	}
	
	
	if(eid > 0){
	//alert(playlistcreatives.length);
	//var fakevar;
	fakevar = playlistcreatives[eid];
	playlistcreatives[eid] = playlistcreatives[eid-1];
	playlistcreatives[eid-1] = fakevar;
	

	var var1div = document.getElementById('menuiconcustom' + eid);
	var var2div = document.getElementById('menuiconcustom' + (eid-1));
	//var1div.style.position = 'absolute';
	//var2div.style.position = 'absolute';
	var topvar1 = var1div.offsetTop;
	var topvar2 = var2div.offsetTop;
	//var1div.style.top = topvar1+'px';
	//var2div.style.top = topvar2+'px';
	//New Method - Transition Baby
	switchfn(eid, eid-1, topvar1, topvar2);
	
	}else{
	doingmoving = false;
	}
	}
}

function switchfn(var1, var2, topvar1, topvar2){
	var var1div = document.getElementById('menuiconcustom' + var1);
	var var2div = document.getElementById('menuiconcustom' + var2);
	clearInterval(var1div.interval);
	if(var1div.offsetTop > topvar2){
	var1div.style.top = var1div.offsetTop - 5 + 'px';
	var2div.style.top = var2div.offsetTop - 1 + 'px';
	var1div.interval = setInterval("switchfn("+var1+","+ var2+","+ topvar1+","+ topvar2+")", 20);
	}
	else{
	updateplaylist();
	doingmoving = false;
	}	 
}

function movedowncreative(eid){
	
	if(doingmoving == false){
	
	doingmoving = true;
	if(eid == currentlylookingatplaylist){
	currentlylookingatplaylist++;
	//alert("hi3");
	} else if(currentlylookingatplaylist == eid+1){
	currentlylookingatplaylist--;
	//alert("hi4");
	}



	if(playlistcreatives.length > eid+1){
	var fakevar;
	fakevar = playlistcreatives[eid];
	playlistcreatives[eid] = playlistcreatives[eid+1];
	playlistcreatives[eid+1] = fakevar;
	//updateplaylist();
	
	var var1div = document.getElementById('menuiconcustom' + eid);
	var var2div = document.getElementById('menuiconcustom' + (eid+1));
	//var1div.style.position = 'absolute';
	//var2div.style.position = 'absolute';
	var topvar1 = var1div.offsetTop;
	var topvar2 = var2div.offsetTop;
	//var1div.style.top = topvar1+'px';
	//var2div.style.top = topvar2+'px';
	//New Method - Transition Baby
	switchfn(eid+1, eid, topvar2, topvar1);
	
	
	} else{
	doingmoving = false;
	}
	}
}


function clickoncustomplaylist(m, n, eid){

	//alert(m);
	//alert(n);
	//alert(id);
	viewcreative(m,n);
	var generatedcreative = document.getElementById("menuiconcustom"+eid);
	generatedcreative.style.border = "4px solid #DDDDDD";
	currentplayselcreative = eid;


}




function removecreative(k){

    if(customplaylist == true){
        //Removes visual playlist
		//alert("hi");
       //document.getElementById("playlist").removeChild(document.getElementById("menuiconcustom"+k));
         //Removes to database
        //playlistcreatives[k] = [];
        //Removes one from further creatives;
        for(m=k;m<playlistcreatives.length-1;m++){
        playlistcreatives[m]=playlistcreatives[m+1];
        }
		
		
		if(k==currentlylookingatplaylist){
		//alert("hi");
			//alert("1");
			if(currentlylookingatplaylist != playlistcreatives.length-1){
			//currentlylookingatplaylist++;
			//alert("in");
			
			
			}
			else if(currentlylookingatplaylist == 0){
			//alert("0");
			//currentlylookingatplaylist++;
			//viewmenucreative(currentlylookingatplaylist);
			} else{
			//Nothing there!
			}
		
		}
		
		if(playlistcreatives.length == 1){
		hideplaylist();
		}		
		playlistcreatives.pop();
		updateplaylist();
		viewmenucreative(currentlylookingatplaylist, currentlylookingatplaylist);

    }
    else{
    }

}
function closewelcometitle(){
document.getElementById("welcome").style.display="none";
}


function goback(){
//Sets Iframe to Blank
var iframevar = document.getElementById("iframecontent");
    frames['iframecontent'].location.href = "blank.html";
	
//opacity("content", 10,0,200);
document.getElementById("pagecontent").style.zIndex = "-1";
hideplaylist();
document.getElementById("welcome").style.display = "none";
//moveright("control", -160, 50);
//movedowncontrol(-60, 10);
//document.getElementById("welcomemain").innerHTML = document.getElementById("actualwelcome").innerHTML;
//document.getElementById("welcometitletext").innerHTML = "Welcome";
document.getElementById("wrapper").style.zIndex = "90";
currentselcreative = 0; //Sections
currentselsection = 0;
currentsection = "welcome";
}



function emailcreative(elem){
var emailhtml='<div id="emailcreative"><div id="title" class="white_content_title">Email Creative</div><div id="contentwhite" class="white_content_content"><div id="closebtn" onclick="closelightbox()"><img src="galleryicons/close26.gif"></div><div id="emailyourname" class="settingstype">Your Name</div><div id="emailyournametxt" onclick="" class="settingstype"><input type="test" name="yourname"></div><div id="emailyouraddress" class="settingstype">Your Email Address</div><div id="emailyouraddresstxt" class="settingstype"><input type="test" name="youremail" style="width:220px"></div><div id="emailtheirname" class="settingstype">Recipient Name</div><div id="emailtheirnametxt" class="settingstype"><input type="test" name="theirname" onChange="javascript:updateemailname(this.value)"></div><div id="emailtheiraddress" class="settingstype">Recipient Email Address</div><div id="emailtheiraddresstxt" onclick="" class="settingstype"><input type="test" name="theiraddress" style="width:220px"></div><div id="emailmaintext" class="settingstype">Message</div><div id="emailmaintexttxt" class="preemailmessage">Hi <div id="hiemail"></div>,<br>    Ive just found this advert in the DoubleClick Rich Media Ad Gallery and I thought it might interest you. Click on the link below to see it.<br> http://innovation.doubleclick.net/index.phtml?viewcreative='+elem+' </div><div id="emailadditionalmessage" class="settingstype">Additional Message</div><div id="emailadditionalmessagetext" class="settingstype"><textarea style="width:460px;height:100px;" name="additionalcontent"></textarea><br><input type="submit" value="Send" onclick="emailcreativeto('+elem+')"></div><div id="creativeid" style="display:none">'+elem+'</div>';
createlightbox(emailhtml, 500, 400);
}

function updateemailname(name){
document.getElementById("hiemail").innerHTML = name;
}

function emailplaylist(elem){



//var elem = 25126216362121;
var XMLvar="'sendemail'";

var emailhtml='<div id="emailcreative"><div id="title" class="white_content_title">Email Your Playlist</div><div id="contentwhite" class="white_content_content"><div id="closebtn" onclick="closelightbox()"><img src="galleryicons/close26.gif"></div><div id="emailyourname" class="settingstype">Your Name</div><div id="emailyournametxt" onclick="" class="settingstype"><input type="test" name="yourname"></div><div id="emailyouraddress" class="settingstype">Your Email Address</div><div id="emailyouraddresstxt" class="settingstype"><input type="test" name="youremail" style="width:220px"></div><div id="emailtheirname" class="settingstype">Recipient Name</div><div id="emailtheirnametxt" class="settingstype"><input type="test" name="theirname" onChange="javascript:updateemailname(this.value)"></div><div id="emailtheiraddress" class="settingstype">Recipient Email Address</div><div id="emailtheiraddresstxt" onclick="" class="settingstype"><input type="test" name="theiraddress" style="width:220px"></div><div id="emailmaintext" class="settingstype">Message</div><div id="emailmaintexttxt" class="preemailmessage">Hi <div id="hiemail"></div>, <br> Ive been looking through the DoubleClick Rich Media Ad Gallery and found a selection of adverts I thought you would like to see, Ive added them into a custom playlist that Ive shared with you. Click on the link below to see them. <div id="playlistlink">http://innovation.doubleclick.net/index.phtml?viewplaylist='+elem+' </div></div><div id="emailadditionalmessage" class="settingstype">Additional Message</div><div id="emailadditionalmessagetext" class="settingstype"><textarea style="width:460px;height:100px;" name="additionalcontent"></textarea><br><input id="emailplaylistsubmit" type="submit" value="Send" onclick="emailplaylistto()"></div><div id="playlistid" style="display:none">'+elem+'</div>';
//<input type="text" style="width:460px" value="http://innovation.doubleclick.net/index.html?viewplaylist='+elem+'" name="playlisttextbox">
createlightbox(emailhtml, 500, 400);
	//if(elem.length > 0){
	if(typeof(elem) == "string"){
		//Not custom
	document.getElementById("playlistlink").innerHTML = "http://innovation.doubleclick.net/index.phtml?viewsectionplaylist="+elem;
	document.getElementById("emailplaylistsubmit").onclick = function(){emailplaylistto('"'+elem+'"')};
	document.getElementById("emailplaylistsubmit").setAttribute("onClick", "emailplaylistto('"+elem+"')");
	}else{
	loadXMLDoc('saveplaylist');
	}
}


function showemailplaylist(){
document.getElementById("emailchoice").style.display = "none";
document.getElementById("emailplaylist").style.display = "block";
}
function showemailcreative(){
document.getElementById("emailchoice").style.display = "none";
document.getElementById("emailcreative").style.display = "block";
}
function showfromcreative(){
document.getElementById("emailchoice").style.display = "block";
document.getElementById("emailcreative").style.display = "none";
}
function showfromplaylist(){
document.getElementById("emailchoice").style.display = "block";
document.getElementById("emailplaylist").style.display = "none";
}

function showgallerysectiondiv(elem){
if(BrowserDetect.browser == "MSIE"| BrowserDetect.browser == "Explorer"){
document.getElementById("bottomshadowmenu").style.zIndex = -1;
	document.getElementById("minimisebottom").style.zIndex = -1;
	//document.getElementById("menucontainer").style.zIndex = -1;
	}


	if(elem.length > 0){
		var e_out; 
		var test = typeof(window.event);
		//alert(test);
		//if(typeof(window.event)!="undefined")? e_out=event.srcElement.id : e_out=evt.target.id; 
		if(typeof(window.event)!="undefined"){
		 if(event.srcElement.id.length > 0){
		 e_out=event.srcElement.id; 
		 var elem = document.getElementById(e_out)
		 	elem = elem.myflag;
		 
		 }
		// if(evt.target.id.length>0){
		 //e_out=evt.target.id.length;
		// } 
		}
		
		//elem.detachEvent('onmouseover', function(){hidegallerysectiondiv("var")});
		//elem.attachEvent('onmouseout',function(){showgallerysectiondiv("var")});
	

	}else{
	//alert(elem);
	//alert('hi');
		var elem = this.myflag;	}
		//alert(elem);
		if(elem.length > 4){
		//alert(elem);
		var currentelem = document.getElementById("gallerymenulist"+elem);
		var currentmenuelem = document.getElementById("gallery"+elem);
		currentmenuelem.className='maingallerymenubuttonhover';

		currentelem.style.display ="block";
		currentelem.style.zIndex = "999991";
		currentelem.style.width = "200" + "px";
		}
	
}


function hidegallerysectiondiv(elem){
if(BrowserDetect.browser == "MSIE"| BrowserDetect.browser == "Explorer"){
	document.getElementById("minimisebottom").style.zIndex = 1020;
	document.getElementById("bottomshadowmenu").style.zIndex = 1020;
	}
	
	//var elem = elem.myflag;
	//alert(this.myflag);
	if(elem.length > 0){
	//alert(elem);
		var e_out; 
		if(typeof(window.event)!="undefined"){
		 if(event.srcElement.id.length > 0){
		 e_out=event.srcElement.id; 
		 var elem = document.getElementById(e_out)
		 	elem = elem.myflag;
		 }
		}
	//elem.detachEvent('onmouseout', function(){showgallerysectiondiv("var")});
	//elem.attachEvent('onmouseover',function(){hidegallerysectiondiv("var")});
	
	}else{
	//alert(elem);
	var elem = this.myflag;	}
	if(elem.length > 4){
	var currentelem = document.getElementById("gallerymenulist"+elem);
	var currentmenuelem = document.getElementById("gallery"+elem);
		currentmenuelem.className='maingallerymenubutton';
	//var currentmenuelem = document.getElementById("gallery"+elem);
	currentelem.style.display = "none";
	currentelem.style.width = "200"+"px";
	}
}

function showsearchsection(elem){
	if(elem.length > 0){
		var e_out; 
		if(typeof(window.event)!="undefined"){
		 if(event.srcElement.id.length > 0){
		 e_out=event.srcElement.id; 
		 var elem = document.getElementById(e_out)
		 	elem = elem.myflag;
		 }
		}
	}else{
	var elem = this.myflag;	}
	var currentelem = document.getElementById("searchinsidesubmenu"+elem);
	currentelem.style.display = "block";
	if(currentelem.addEventListener){ 
			currentelem.addEventListener('click', hidesearchsection, false);
			
			currentelem.myflag = elem;
		}else{  //IE
			currentelem.attachEvent('onclick', function(){hidesearchmenu();}, false);
			currentelem.myflag = elem;
		} 
		
	var secondelem = document.getElementById("searchinsidemenudiv"+elem);
	secondelem.style.backgroundColor = "#CCCCCC";
	if(BrowserDetect.browser == "Chrome" | BrowserDetect.browser == "Safari"){
	secondelem.style.width = document.getElementById("mainmenubuttonall").offsetWidth +2 + "px";
	secondelem.style.borderRight = "solid 1px #959595";
	secondelem.style.left = "0px";
	currentelem.style.left = "-152px";
	}
	var currentarrow = document.getElementById("leftarrow"+elem);
	currentarrow.src = "galleryicons/leftmenuarrowwhite.gif";
	
	
	showsearchmenu();	
}

function shownewsearchsection(elem){
	if(elem.length > 0){
		var e_out; 
		if(typeof(window.event)!="undefined"){
		 if(event.srcElement.id.length > 0){
		 e_out=event.srcElement.id; 
		 var elem = document.getElementById(e_out)
		 	elem = elem.myflag;
		 }
		}
	}else{
	var elem = this.myflag;	}
	var currentelem = document.getElementById("newsearchinsidesubmenu"+elem);
	currentelem.style.display = "block";
	shownewsearchmenu();	
}

function hidesearchsection(elem){
	if(elem.length > 0){
		var e_out; 
		if(typeof(window.event)!="undefined"){
		 if(event.srcElement.id.length > 0){
		 e_out=event.srcElement.id; 
		 var elem = document.getElementById(e_out)
		 	elem = elem.myflag;
		 }
		}
	}else{
	var elem = this.myflag;	}
	var currentelem = document.getElementById("searchinsidesubmenu"+elem);
	currentelem.style.display = "none";
	var secondelem = document.getElementById("searchinsidemenudiv"+elem);
	secondelem.style.backgroundColor = "#EBEBEB";
	var currentarrow = document.getElementById("leftarrow"+elem);
	currentarrow.src = "galleryicons/blackmenuarrowwhite.gif";
}

function hidenewsearchsection(elem){
	if(elem.length > 0){
		var e_out; 
		if(typeof(window.event)!="undefined"){
		 if(event.srcElement.id.length > 0){
		 e_out=event.srcElement.id; 
		 var elem = document.getElementById(e_out)
		 	elem = elem.myflag;
		 }
		}
	}else{
	var elem = this.myflag;	}
	var currentelem = document.getElementById("newsearchinsidesubmenu"+elem);
	currentelem.style.display = "none";
}


function generategallerymenu(){
		var container = document.getElementById("middlecontainer");
	

		//Main Menu bit
		var newdiv = document.createElement('div');
  		newdiv.setAttribute('id', "mainmenu");
		container.appendChild(newdiv);
		
		//var newdiv2 = document.createElement('div');
		//newdiv2.className = "mainmenutitlespotlight";
		//newdiv2.innerHTML = "CREATIVE SPOTLIGHT: ";
		//newdiv.appendChild(newdiv2);
		
		/*var newdiv3 = document.createElement('div');
		newdiv3.className="spotlightleftmenu";
		newdiv3.innerHTML = "<img src='galleryicons/spotlightleft.gif'>";
		newdiv.appendChild(newdiv3);
		
		var newdiv3 = document.createElement('div');
		newdiv3.className="spotlightrightmenu";
		newdiv3.innerHTML = "<img src='galleryicons/spotlightright.gif'>";
		newdiv.appendChild(newdiv3);*/
		
		for(j=1; j < allgallerycreativessections[0].length; j++){
		var newdiv2 = document.createElement('div');
		newdiv2.className = "mainmenubutton";
		if(j==1){
			newdiv2.className = "mainmenubuttonsmall";	
		}
		newdiv2.setAttribute('id', 'mainmenubutton');
		//newdiv2.setAttribute("onclick", "showgallerysubsection('"+ allgallerycreativessections[0][j][0]+"')");
		//newdiv2.onclick = function(){showgallerysubsection("menu")};
		newdiva = document.createElement('a');
		newdiva.href = "javascript:showgallerysubsection('"+ allgallerycreativessections[0][j][0]+"')";
		if(allgallerycreativessections[0][j][1] == "YouTube"){
			newdiv2.innerHTML = "<img src='galleryicons/YT_noborder.jpg'>";
			newdiv2.style.padding = "3px";
		}else{
		newdiv2.innerHTML = allgallerycreativessections[0][j][1];
		}
		newdiva.appendChild(newdiv2);
		newdiv.appendChild(newdiva);
		//if(j<allgallerycreativessections[0].length-1){
		newdiv3 = document.createElement('div');
		newdiv3.className = "menudivider";
		newdiv3.innerHTML =  "<img src='galleryicons/transparentdivider.gif'>";
		newdiv.appendChild(newdiv3);
		//}
		
		
		}
		/*newdiv3 = document.createElement('div');
		newdiv3.className = "menudivider";
		newdiv3.innerHTML =  "<img src='galleryicons/transparentdivider.gif'>";
		newdiv.appendChild(newdiv3); */
		//Latest News
		/*
		var newdiv2 = document.createElement('div');
		newdiv2.className = "mainmenubutton";
		newdiv2.setAttribute('id', 'mainmenubuttonlatest');
		newa = document.createElement('a');
		newa.href = "javascript:showgallerysubsection('innoall')";
		newdiv2.innerHTML = "All";
		newa.appendChild(newdiv2);
		newdiv.appendChild(newa);
		newdiv3 = document.createElement('div');
		newdiv3.className = "menudivider";
		newdiv3.innerHTML =  "<img src='galleryicons/transparentdivider.gif'>";
		newdiv.appendChild(newdiv3); */
		
		var newdiv2 = document.createElement('div');
		newdiv2.className = "mainmenubutton";
		newdiv2.setAttribute('id', 'mainmenubuttonlatest');
		newa = document.createElement('a');
		newa.href = "javascript:showlatest()";
		newdiv2.innerHTML = "Latest News";
		newa.appendChild(newdiv2);
		newdiv.appendChild(newa);
		
		
		
		
		//Ad Gallery
		var newdiv2 = document.createElement('div');
		newdiv2.className = "mainmenubutton";
		newdiv2.setAttribute('id', 'mainmenubuttonall');
		newa = document.createElement('a');
		newa.href = "javascript:showsearchmenu()";
		newdiv2.innerHTML = "All <img id='adgalleryarrow' src='galleryicons/whitedownarrow.gif'>";
		newa.appendChild(newdiv2);
		newdiv.appendChild(newa);
		
		if(newdiv2.addEventListener){ 
			newdiv2.addEventListener('mouseout', hidesearchmenu, false);
			newdiv2.addEventListener('mouseover', showsearchmenu,false);
		}else{  //IE
			newdiv2.attachEvent('onmouseleave', function(){hidesearchmenu()}, false);
			newdiv2.attachEvent('onmouseover',function(){showsearchmenu()}, false);
		} 
		
		
		//var newhr = document.createElement('hr');
		//newhr.setAttribute('id', 'menudivider');
		//container.appendChild(newhr);


}

function blank(){
//alert('hi');
}



function generatesearchmenu(){

	var searchseaction = document.getElementById("mainmenubuttonall");
	var newdiv = document.createElement('div');
  		newdiv.setAttribute('id', "searchinsidemenu");
		newdiv.setAttribute('class', 'searchinsidemenu');
		newdiv.className = 'searchinsidemenu';
		newdiv.onmouseout = 'hidesearchmenu()';
		newdiv.style.position = 'absolute';
		
		if(newdiv.addEventListener){ 
		newdiv.addEventListener('mouseout',hidesearchmenu,false) ; 
		}else{ 
		newdiv.attachEvent('onmouseleave',function(){hidesearchmenu('var')}); 
		} 
		searchseaction.appendChild(newdiv);
		
		
			
		
		for(j=1; j <allgallerycreativessections.length; j++){ //Each Section
			var newdiv2 = document.createElement('div');
			newdiv2.setAttribute('id', 'searchinsidemenudiv'+j);
			newdiv2.setAttribute('class', 'searchinsidemenudiv');
			newdiv2.className = 'searchinsidemenudiv';
			newdiv2.innerHTML = '<img id="leftarrow'+j+'" src="galleryicons/blackmenuarrowwhite.gif">'+allgallerycreativessections[j][0][1];
					if(newdiv2.addEventListener){ 
					newdiv2.addEventListener('mouseout', hidesearchsection,false);
					newdiv2.addEventListener('mouseover', showsearchsection,false);
					newdiv2.myflag = j;
					}else{ 
					newdiv2.attachEvent('onmouseleave', function(){hidesearchsection("var")}, false);
					newdiv2.attachEvent('onmouseenter',function(){showsearchsection("var")}, false);
					newdiv2.myflag = j;
					} 

			var newdiv3 = document.createElement('div');
			newdiv3.setAttribute('id', 'searchinsidesubmenu'+j);
			newdiv3.setAttribute('class', 'searchinsidesubmenu');
			newdiv3.className = 'searchinsidesubmenu';
			newdiv3.style.position = 'absolute';
			newdiv2.appendChild(newdiv3);
			newdiv.appendChild(newdiv2);
			for(k=1; k < allgallerycreativessections[j].length; k++){
				var newdiv4 = document.createElement('div');
				//newdiv4.setAttribute('id', 'searchinsidesubmenudiv'+k);
				newdiv4.setAttribute('id', 'searchinsidesubmenudiv'+j+"-"+k);
				newdiv4.setAttribute('class', 'searchinsidesubmenudiv');
				newdiv4.className = 'searchinsidesubmenudiv';
				newdiv4.innerHTML = allgallerycreativessections[j][k][1];
				newa5 = document.createElement('a');
				
				newa5.setAttribute("id", "searchinsidea");
				newa5.id = "searchinsidea";
				//newa5.setAttribute('id', 'searchinsidesubmenudiv'+j+"-"+k);
				//newa5.setAttribute('class', 'searchinsidea');
				//newa5.className = 'searchinsidea';
				newa5.href = "javascript:showgallerysubsection('"+allgallerycreativessections[j][k][0]+"')";
				//newa5.appendChild(document.createTextNode(allgallerycreativessections[j][k][1]));
				newa5.appendChild(newdiv4); 

				//newdiv4.innerHTML = "<a href=javascript:showgallerysubsection('"+allgallerycreativessections[j][k][0]+"')>"+allgallerycreativessections[j][k][1]+"</a>";
				newdiv3.appendChild(newa5);
				
				
				if(newdiv4.addEventListener){ 
				newdiv4.addEventListener('mouseout', unhighlightsubsection,false);
				newdiv4.addEventListener('mouseover', highlightsubsection,false);
				newdiv4.myflag = j+"-"+k;
				}else{ 
				newdiv4.attachEvent('onmouseleave', function(){unhighlightsubsection("var")}, false);
				newdiv4.attachEvent('onmouseenter',function(){highlightsubsection("var")}, false);
				newdiv4.myflag = j+"-"+k;
				} 
				
				

			}
		}
		var newdiv2 = document.createElement('div');
			newdiv2.setAttribute('id', 'searchinsidemenudivall');
			//newdiv2.setAttribute('class', 'searchinsidemenudiv');
			newdiv2.className = 'searchinsidemenudiv';
			randvar = "'innoall'"
			newdiv2.innerHTML = '<a href="javascript:showgallerysubsection('+randvar+')"><img id="allcreativeimg" src="galleryicons/menublackbox.gif">All Creatives</a> ';
			//newdiv2.id = "searchinsidea";
					if(newdiv2.addEventListener){ 
					newdiv2.addEventListener('mouseout', unhighlightallsection,false);
					newdiv2.addEventListener('mouseover', highlightallsection,false);
					newdiv2.myflag = j;
					}else{ 
					newdiv2.attachEvent('onmouseleave', function(){unhighlightallsection("var")}, false);
					newdiv2.attachEvent('onmouseenter',function(){highlightallsection("var")}, false);
					newdiv2.myflag = j;
					} 	
			newdiv.appendChild(newdiv2);
			
			
			
}

function highlightallsection(){
	var currentelem = document.getElementById("searchinsidemenudivall");
	currentelem.style.backgroundColor = "#CCCCCC";
	var currentimg = document.getElementById("allcreativeimg");
	currentimg.src="galleryicons/menuwhitebox.gif";	
}
function unhighlightallsection(){
	var currentelem = document.getElementById("searchinsidemenudivall");
	currentelem.style.backgroundColor = "";
	var currentimg = document.getElementById("allcreativeimg");
	currentimg.src="galleryicons/menublackbox.gif";
}
function highlightsubsection(elem){
		if(elem.length > 0){
		var e_out; 
		if(typeof(window.event)!="undefined"){
		 if(event.srcElement.id.length > 0){
		 e_out=event.srcElement.id; 
		 var elem = document.getElementById(e_out)
		 	elem = elem.myflag;
		 }
		}
	}else{
	var elem = this.myflag;	}
	var currentelem = document.getElementById("searchinsidesubmenudiv"+elem);
	currentelem.style.backgroundColor = "#AAAAAA";
}

function unhighlightsubsection(elem){
			if(elem.length > 0){
		var e_out; 
		if(typeof(window.event)!="undefined"){
		 if(event.srcElement.id.length > 0){
		 e_out=event.srcElement.id; 
		 var elem = document.getElementById(e_out)
		 	elem = elem.myflag;
		 }
		}
	}else{
	var elem = this.myflag;	}
	var currentelem = document.getElementById("searchinsidesubmenudiv"+elem);
	currentelem.style.backgroundColor = "";
	
}


function generatenewsearchmenu(){

	var searchseaction = document.getElementById("newsearchcontainer");
	var newdiv = document.createElement('div');
  		newdiv.setAttribute('id', "newsearchinsidemenu");
		newdiv.setAttribute('class', 'newsearchinsidemenu');
		newdiv.className = 'newsearchinsidemenu';
		newdiv.onmouseout = 'hidenewsearchmenu()';
		newdiv.style.position = 'absolute';
		
		if(newdiv.addEventListener){ 
		newdiv.addEventListener('mouseout',hidenewsearchmenu,false) ; 
		}else{ 
		newdiv.attachEvent('onmouseleave',function(){hidenewsearchmenu('var')}); 
		} 

		searchseaction.appendChild(newdiv);
		for(j=0; j <allgallerycreativessections.length; j++){ //Each Section
			var newdiv2 = document.createElement('div');
			newdiv2.setAttribute('id', 'newsearchinsidemenudiv'+j);
			newdiv2.setAttribute('class', 'newsearchinsidemenudiv');
			newdiv2.className = 'newsearchinsidemenudiv';
			newdiv2.innerHTML = '<img src="galleryicons/left_arrow.gif">'+allgallerycreativessections[j][0][1];
					if(newdiv2.addEventListener){ 
					newdiv2.addEventListener('mouseout', hidenewsearchsection,false);
					newdiv2.addEventListener('mouseover', shownewsearchsection,false);
					newdiv2.myflag = j;
					}else{ 
					newdiv2.attachEvent('onmouseleave', function(){hidenewsearchsection("var")}, false);
					newdiv2.attachEvent('onmouseenter',function(){shownewsearchsection("var")}, false);
					newdiv2.myflag = j;
					} 

			var newdiv3 = document.createElement('div');
			newdiv3.setAttribute('id', 'newsearchinsidesubmenu'+j);
			newdiv3.setAttribute('class', 'newsearchinsidesubmenu');
			newdiv3.className = 'newsearchinsidesubmenu';
			newdiv3.style.position = 'absolute';
			newdiv2.appendChild(newdiv3);
			newdiv.appendChild(newdiv2);
			for(k=1; k < allgallerycreativessections[j].length; k++){
				var newdiv4 = document.createElement('div');
				newdiv4.setAttribute('id', 'newsearchinsidesubmenudiv'+k);
				newdiv4.setAttribute('class', 'newsearchinsidesubmenudiv');
				newdiv4.className = 'newsearchinsidesubmenudiv';
				newdiv4.innerHTML = '<a href=javascript:changenewsearchlocation("'+allgallerycreativessections[j][k][0]+'")>'+allgallerycreativessections[j][k][1]+'</a>';
				newdiv3.appendChild(newdiv4);
			
			}
		}
			var newdiv2 = document.createElement('div');
			newdiv2.setAttribute('id', 'newsearchinsidemenudivall');
			//newdiv2.setAttribute('class', 'searchinsidemenudiv');
			newdiv2.className = 'newsearchinsidemenudiv';
			randvar = "'innoall'"
			newdiv2.innerHTML = '<a href="javascript:changenewsearchlocation('+randvar+')"><img src="galleryicons/left_arrow.gif">All Creatives</a> ';
					if(newdiv2.addEventListener){ 
					newdiv2.addEventListener('mouseover', shownewsearchmenu,false);
					}else{ 
					newdiv2.attachEvent('onmouseenter',function(){shownewsearchmenu("var")}, false);
					} 	
			newdiv.appendChild(newdiv2);
}

function showsearchmenu(){
	document.getElementById("searchinsidemenu").style.display = "block";
	document.getElementById("mainmenubuttonall").className = "mainmenubuttonallover";
	document.getElementById("mainmenubuttonall").style.background = "url(galleryicons/trans.gif)";
	document.getElementById("mainmenubuttonall").style.backgroundColor = "#EBEBEB";
	document.getElementById("mainmenubuttonall").style.color = "#000000";
	document.getElementById("adgalleryarrow").src = "galleryicons/blackdownarrow.gif";
	//if(BrowserDetect.browser == "MSIE" | BrowserDetect.browser == "Explorer"){
document.getElementById("searchinsidemenu").style.width = document.getElementById("mainmenubuttonall").offsetWidth+"px";
if(BrowserDetect.browser == "Chrome" | BrowserDetect.browser == "Safari"){
document.getElementById("searchinsidemenu").style.width = document.getElementById("mainmenubuttonall").offsetWidth - 2 + "px";	
}

//}
	//alert("hi");
}

function shownewsearchmenu(){
	document.getElementById("newsearchinsidemenu").style.display = "block";
	//alert("hi");
}

function hidesearchmenu(){
	var currentelem = document.getElementById("searchinsidemenu");
	currentelem.style.display = "none";
	document.getElementById("mainmenubuttonall").className = "mainmenubutton";
	document.getElementById("mainmenubuttonall").style.background = "url(galleryicons/menubggreen.gif)";
	document.getElementById("mainmenubuttonall").style.backgroundColor = "#CCCCCC";
	document.getElementById("mainmenubuttonall").style.color = "#FFFFFF";
	document.getElementById("adgalleryarrow").src = "galleryicons/whitedownarrow.gif";	
}


function hidenewsearchmenu(){
	var currentelem = document.getElementById("newsearchinsidemenu");
	currentelem.style.display = "none";
}

function changesearchlocation(eid){
	if(eid == "innoall"){
	document.getElementById("searchseaction").innerHTML = "All Creatives";
	document.getElementById("newsearchseaction").innerHTML = "All Creatives";
	searchinside = "innoall";
	hidesearchmenu();
	}else{
	var foundsearch = false;
	searchinside = eid;
		for(m = 0; m < (allgallerycreativessections.length); m++){
				for(n = 1; n < (allgallerycreativessections[m].length); n++){
					if(allgallerycreativessections[m][n][0]==eid){
						document.getElementById("searchseaction").innerHTML = allgallerycreativessections[m][n][1]+'';
						document.getElementById("newsearchseaction").innerHTML = allgallerycreativessections[m][n][1]+'';
						hidesearchmenu();
						foundsearch = true;
					}
				}
		}
	if(foundsearch == false){
	} 
	}
}

function changenewsearchlocation(eid){
	if(eid == "innoall"){
	document.getElementById("searchseaction").innerHTML = "All Creatives";
	document.getElementById("newsearchseaction").innerHTML = "All Creatives";
	searchinside = "innoall";
	hidenewsearchmenu();
	}else{
	var foundsearch = false;
	searchinside = eid;
		for(m = 0; m < (allgallerycreativessections.length); m++){
				for(n = 1; n < (allgallerycreativessections[m].length); n++){
					if(allgallerycreativessections[m][n][0]==eid){
					document.getElementById("searchseaction").innerHTML = allgallerycreativessections[m][n][1]+'';
						document.getElementById("newsearchseaction").innerHTML = allgallerycreativessections[m][n][1]+'';
						hidenewsearchmenu();
						foundsearch = true;
					}
				}
		}
	if(foundsearch == false){
	} 
	}
}

function playlisttorecent(){
	customplaylist = false;
	lastviewplaylist = true;
	//alert("hi");
	updateplaylist();
}
function playlisttosection(){
	customplaylist = false;
	lastviewplaylist = false;
	updateplaylist();
}

function playlisttocustom(){
	customplaylist = true;
	lastviewplaylist = false;
	//customplaylistfn();
	updateplaylist();
}



function showgallerysubsection(gotid){
//check if same section



	var checkvar = document.getElementById("welcome");
	checkvar.style.zIndex = 260;
	checkvar.style.display="block";
	
	//Makes sure window size is right
	resizewelcomecheck();
	
	document.getElementById("welcomebottom").style.display = "block";
	
	if(currentselsection == gotid){
	}
	/*else if(checkvar.style.display == "none"){

	opacity("welcomemain", 1, 0, 500);
	}*/
	else{
	currentselsection = gotid;
	var id = "welcomemain";
	/*var opacStart = 95;
	var opacEnd = 0;
	var millisec = 500;
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
*/
		currentelem = document.getElementById("welcomemain");
		currentelem.interval = setInterval("checkerscriptgallery('" + gotid + "')", 100); 
	} 
	

}

function checkerscriptgallery(gotid){
			currentelem = document.getElementById("welcomemain");
			clearInterval(currentelem.interval);
				//if(currentelem.curopacity <= 0){ //DISAPPEARED SO DO STUFF!
					var welcomemain = document.getElementById("welcomemain");
					welcomemain.innerHTML = "";
					//alert(gotid);
					if(gotid == "innoall"){ //Show all innovation gallery ones
					   //currentselsection = -1;
					   //alert("3");
                        currentelem2 = document.getElementById("welcometitletext");
						currentelem2.innerHTML = "All Creatives";
						//
						
						for(n=0; n <allgallerycreatives.length;n++){
						//alert(allgallerycreatives[n][10]);
							generategallerycreative('creativemain'+n, n, 'welcomemain');
							foundresults = true;
						}

					}else{
					
					
					currentelem2 = document.getElementById("welcometitletext");
					//Find Title;
					
					for(n=0; n < allgallerycreativessections.length;n++){
						for(m=0; m < allgallerycreativessections[n].length;m++){
							if(allgallerycreativessections[n][m][0]==gotid){
								currentelem2.innerHTML = allgallerycreativessections[n][m][1];
							}
						}
					}
					
					if(gotid == "innoyoutube"){
					currentelem2 = document.getElementById("welcometitletext");
					currentelem2.innerHTML = "<img src='galleryicons/YT_larger.jpg'>";
					}
					
					//Check if Innovation Link:
					if(gotid.search("inno") == 0){
					//Check 10th element
						for(n=0; n < allgallerycreatives.length;n++){
						
						gotid2 = gotid.substring(4, gotid.length);
						//alert(gotid2);
							if(allgallerycreatives[n][12] == 1){
							//var checkvar = (allgallerycreatives[n][9].toLowerCase()+","+allgallerycreatives[n][8].toLowerCase()+","+allgallerycreatives[n][13].toLowerCase()+","+allgallerycreatives[n][5].toLowerCase()).search(gotid2);
							//if(checkvar > -1){
							var checkvar = (allgallerycreatives[n][15].toLowerCase().search(gotid2));
							if(checkvar > -1){
                            generategallerycreative('creativemain'+n, n, 'welcomemain');
                            foundresults = true;
							}
							}
						}
					
					
					
					}
					else{ //Check normal tags
					
						for(n=0; n < allgallerycreatives.length;n++){
							var checkvar = (allgallerycreatives[n][9].toLowerCase()+","+allgallerycreatives[n][8].toLowerCase()+","+allgallerycreatives[n][13].toLowerCase()+","+allgallerycreatives[n][5].toLowerCase()).search(gotid);
								if(checkvar > -1){
                            		generategallerycreative('creativemain'+n, n, 'welcomemain');
                            	foundresults = true;
							}
						}
					}
					}
				
					
					//opacity("welcomemain", 0, 95, 500);


			//}
			//else{
			//alert("hi");
			//currentelem.interval = setInterval("checkerscriptgallery('" + gotid + "')", 100); 

			//}

		}
		
		
		
		//TO DO
		
		function showcreativeinfo(elem){
		//Get appropriate creative
		if(gallerytype == false){ //FULL GALLERY
		
		//currentelem = allgallerycreatives[currentselcreative];
		
		}else{ //Innovation Gallery
		
		//currentelem = allcreatives[currentselsection][currentselcreative];
		
		
		}
		//Show Lightbox
		/*
		var creativehtml='<div id="title" class="white_content_title">Creative Details<div id="closebtn" onclick="closelightbox()"><a href="javascript:closelightbox()"><img src="galleryicons/close26.gif"></div></a></div><div id="background" class="creativetitle">Creative Name</div><div id="background" class="creativeinfo">'+currentelem[0]+'</div><div id="background" class="creativetitle">Creative Agency</div><div id="background" class="creativeinfo">'+currentelem[2]+'</div><div id="background" class="creativetitle">Media Agency</div><div id="background" class="creativeinfo">'+currentelem[1]+'</div><div id="background" class="creativetitle">Client</div><div id="background" class="creativeinfo">'+currentelem[7]+'</div><div id="background" class="creativetitle">Info</div><div id="background" class="creativeinfo">'+currentelem[6]+'</div><div id="background" class="creativetitle">Tags</div><div id="background" class="creativeinfo">'+currentelem[9]+'</div>';*/
		
		
		/* OLD VERSION 
		var creativehtml='<a href="javascript:closelightbox()"><img src="galleryicons/CREATIVE_DETAILS.jpg"></a>';
		
		allgallerycreatives[12] = new Array();
allgallerycreatives[12][0] = "Hot Spot";
allgallerycreatives[12][1] = "Agency Republic";
allgallerycreatives[12][2] = "I-Level";
allgallerycreatives[12][3] = "http://innovation.doubleclick.net/creatives/coi_stop_smoking/galindex.html";
allgallerycreatives[12][4] = "galleryicons/advanced_video.jpg";
allgallerycreatives[12][9] = "hotspot, expand, video, smoking, coi, government, agency republic, i-level, ilevel, i level, emea";
allgallerycreatives[12][6] = "With engaging content, users peel back the content from behind the web page. The video page peel creates a less intrusive method for interacting with the user to deliver a message.";
allgallerycreatives[12][7] = "COI";
allgallerycreatives[12][8] = "http://www.agencyrepublic.com ";
allgallerycreatives[12][9] = "http://www.i-level.com" ;
allgallerycreatives[12][10] = "innoadvanced" ;		
		
		*/
		var creativefullbrief = "'creativefullbrief'";
		var creativefullformat = "'creativefullformat'";
		var creativefullfeatures = "'creativefullfeatures'";
		var creativefullcollateral = "'creativefullcollateral'";
		var creativefulllabels = "'creativefulllabels'";
		var currentelem = allgallerycreatives[elem];
		
		var creativehtml='<div id="title" class="white_content_title">Creative Details</div><div id="contentwhite" class="white_content_content"><div id="closebtn" onClick="closelightbox()"><img src="galleryicons/close26.gif"></div><div class="creativedetaildetails">	<div class="creativenametxt">Creative Name:</div><div class="creativename">'+currentelem[0]+'</div>    <div class="creativeclienttxt">Client:</div><div class="creativecliente">'+currentelem[7]+'</div>    <div class="creativecreativetxt">Media Agency:</div><div class="creativecreative">'+currentelem[1]+'</div>    <div class="creativemediatxt">Creative Agency:</div><div class="creativemedia">'+currentelem[2]+'</div>	<div class="creativesizetxt">Format:</div><div class="creativesize">'+currentelem[5]+'</div>    <div class="creativeformattxt"></div><div class="creativeformat"></div></div><!--<div class="creativemoredetails">	<div class="creativeleftmenu">    	<div id="creativefullbrieftext" class="creativemenuselected"><a href="javascript:changecreativesection('+creativefullbrief+')"> CREATIVE BRIEF</a></div>        <div id="creativefullformattext" class="creativemenuunselected"><a href="javascript:changecreativesection('+creativefullformat+')">  FORMAT</a></div>        <div id="creativefullfeaturestext" class="creativemenuunselected"><a href="javascript:changecreativesection('+creativefullfeatures+')">  FEATURES</a></div>        <div id="creativefulllabelstext" class="creativemenuunselected"><a href="javascript:changecreativesection('+creativefulllabels+')">  LABELS</a></div>        <div id="creativefullcollateraltext"class="creativemenuunselected"><a href="javascript:changecreativesection('+creativefullcollateral+')">  COLLATERAL</a></div>      </div>      <div class="creativerightmenu">      	<div id="creativefullbrief">'+currentelem[6]+'</div>        <div id="creativefullformat" style="display:none">'+currentelem[10]+'</div>        <div id="creativefullfeatures" style="display:none">'+currentelem[9]+'</div>       <div id="creativefulllabels" style="display:none"> INSERT </div>        <div id="creativefullcollateral" style="display:none"> INSERT </div>       </div></div><div class="creativehelpbutton"><img src="galleryicons/help.png"></div></div> -->';
		
createlightbox(creativehtml, 600, 200);

		}
		
		
		function searchclicked(){
		if(searchalreadyclicked == false){
		//Change Formatting to Normal
		searchalreadyclicked = true;
		var searchelem = document.getElementById("searchtext");
		searchelem.style.color = "#121212";
		searchelem.style.backgroundColor = "#FFFFFF";
		searchelem.value = "";
		}
		}
		
		function newsearchclicked(){
		if(newsearchalreadyclicked == false){
		//Change Formatting to Normal
		newsearchalreadyclicked = true;
		var searchelem = document.getElementById("newsearchtext");
		searchelem.style.color = "#121212";
		searchelem.style.backgroundColor = "#FFFFFF";
		searchelem.value = "";
		}
		}
		
		
		function createcustomplaylist(){
		//Do Stuff
		
		//Light Box
		//	var playlisthtml='<div id="title" class="white_content_title">Custom Playlist</div><div id="blah" class="white_content_content"><div id="closebtn" onclick="closelightbox()"><img src="galleryicons/close26.gif"></div><div class="playlistinfo">Custom Playlistes allow you to create custom playlists dynamically inside the Innovation Gallery. You can add creatives using the plus icon next to each one, or remove them from the menu on the right. If you would like to save this menu at any time click on the email button, and we can send you a link to return back to that playlist at any time</div> <div class="playlistinfo">To add creatives to this Playlist please select the "+" symbol next to each creative</div> <div class="playlistinfo">To remove creatives in this Playlist please select the "-" symbol next to each creative</div> <div class="playlistinfo">To move creatives in this Playlist please select the "<" & ">" symbols on each creative</div>';
			//createlightbox(playlisthtml, 400, 300);
			/*
			
			 <div id="addcreativespeal" class="creativeclass">To add creatives to this Playlist please select the "+" symbol next to each creative</div><div id="removecreativespeal" class="creativeclass">To remove creatives in this Playlist please select the "-" symbol next to each creative</div><div id="movecreativespeal" class="creativeclass">To move creatives in this Playlist please select the "<" & ">" symbols on each creative</div>
			 
							var playlistdiv = document.getElementById("playlistinfo");
			  				var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', "addcreativespeal");
							newdiv.setAttribute('class', 'creativeclass');
							newdiv.className = 'creativeclass';
							newdiv.style.left = "2px";
							newdiv.style.top="50px";
							newdiv.style.width = "140px";
							newdiv.style.height = "70px";
							newdiv.innerHTML = "To add creatives to this Playlist please select the '+' symbol next to each creative.";
							playlistdiv.appendChild(newdiv);
							
							var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', "removecreativespeal");
							newdiv.setAttribute('class', 'creativeclass');
							newdiv.className = 'creativeclass';
							newdiv.style.left = "2px";
							newdiv.style.top="50px";
							newdiv.style.width = "140px";
							newdiv.style.height = "70px";
							newdiv.innerHTML = "To remove creatives in this Playlist please select the '-' symbol next to each creative.";
							playlistdiv.appendChild(newdiv);
							
							var newdiv = document.createElement('div');
  							newdiv.setAttribute('id', "removecreativespeal");
							newdiv.setAttribute('class', 'creativeclass');
							newdiv.className = 'creativeclass';
							newdiv.style.left = "2px";
							newdiv.style.top="50px";
							newdiv.style.width = "140px";
							newdiv.style.height = "70px";
							newdiv.innerHTML = "To move creatives in this Playlist please select the '<' & '>' symbols on each creative.";
							playlistdiv.appendChild(newdiv); */
		
		//Show Playlist
		
		//Set to custom
    		showplaylist();
			customplaylist = true;
			previousplaylist = false;
			updateplaylist();
			addedbefore = true;
		
		
		}
		
function changecreativesection(elem){
//Set all buttons to blank
document.getElementById("creativefullbrieftext").className = "creativemenuunselected";
document.getElementById("creativefullformattext").className = "creativemenuunselected";
document.getElementById("creativefullfeaturestext").className = "creativemenuunselected";
document.getElementById("creativefulllabelstext").className = "creativemenuunselected";
document.getElementById("creativefullcollateraltext").className = "creativemenuunselected";
//Set all content to blank
document.getElementById("creativefullbrief").style.display = "none";
document.getElementById("creativefullformat").style.display = "none";
document.getElementById("creativefullfeatures").style.display = "none";
document.getElementById("creativefulllabels").style.display = "none";
document.getElementById("creativefullcollateral").style.display = "none";

//show element
document.getElementById(elem).style.display = "block";
//put menu item to selected
document.getElementById(elem + "text").className = "creativemenuselected";

}

function setplaylistlocation(){
var currentplay = document.getElementById("playlistcontainer");
	if(currentplay.offsetTop > 200){
	currentplay.style.top = windowSize().height+10+"px";

		//currentelem.interval = setInterval("hideplaylist()", 2); 
	}
	else{
//currentplay.style.top = windowSize().height+10+"px";
	//showplaylist();
}

resizewelcomecheck();
setplaylistheight();
}

function login(){
//Checker

loggedin();
//alert('hi');

}

function forgottenpass(){
var changearea = document.getElementById("logininfo");

changearea.innerHTML = '<div id="forgottenemail"> Email to send password </div> <div id="forgottenemailtxt"><input type="text" name="forgottenemailtxtbox"></div><div id="sendpassword"> Send </div>';

}

function register(){

}

function loggedin(){
var changearea = document.getElementById("logininfo");
changearea.innerHTML = '<div id="loggedin"> Thankyou for  NAME for logging in - Click to close </div>';
var changearea = document.getElementById("title");
changearea.onclick = "javascript:closelightbox()";
}
function backlogin(){
var registerpage = "'registerpage'";
var changearea = document.getElementById("logininfo");
changearea.innerHTML = '<div id="loginemail"> Email:</div><div id="loginemailtxt"><input type=text id="loginemailtxtbox"></div> <div id="loginpassword"> Password:</div><div id="loginpasswordtxt"><input type=text id="loginpasswordtxtbox"></div> <div id="register" onClick="login()">Login</div> <div id="register" onClick="changelogin('+registerpage+')">Register</div> <br><br><div id="forgottenpassword"> <a href="javascript:forgottenpass()">Forgotten your password?</a></div>';
}

function showlogin(){
var registerpage = "'registerpage'";
var loggedin = "'loggedin'";
			var loginhtml='<div id="title" class="white_content_title">Login<div id="closebtn" onclick="closelightbox()"><img src="galleryicons/close26.gif"></div></div><div id="logininfo" class="logininfo"> <div id="loginemail"> Email:</div><div id="loginemailtxt"><input type=text id="loginemailtxtbox"></div> <div id="loginpassword"> Password:</div><div id="loginpasswordtxt"><input type=text id="loginpasswordtxtbox"></div> <div id="register" onClick="login()">Login</div> <div id="register" onClick="changelogin('+registerpage+')">Register</div> <br><br><div id="forgottenpassword"> <a href="javascript:forgottenpass()">Forgotten your password?</a></div> </div>';
			createlightbox(loginhtml, 400, 300);
}

function changelogin(typ){
var changearea = document.getElementById("logininfo");
if(typ=="passwordwrong"){
changearea.innerHTML = '<div id="passwordwrong"> Unfortunatey your password or email is incorrect, please try again below</div><div id="loginemail> Email:</div><div id="loginemailtxt"><input type="text" name="loginemailtxtbox"></div> <div id="loginpassword"> Password:</div><div id="loginpasswordtxt"><input type="text" name="loginpasswordtxtbox"></div> <div id="register">Register</div><div id="forgotten"> Forgotten your password?</div>';


} else if(typ=="registerpage"){

changearea.innerHTML = '<div id="registerfirstname" class="registerbox">First Name: </div><div id="registerfirstnametxt" class="registerbox"> <input type="text" name="registerfirstnametxtbox"></div> <div id="registerlastname" class="registerbox">Last Name: </div><div id="registerlastnametxt" class="registerbox"> <input type="text" name="registerlastnametxtbox"></div>  <div id="registercompany" class="registerbox">Company: </div><div id="registercompanytxt" class="registerbox"> <input type="text" name="registercompanyetxtbox"></div> <div id="registeremail" class="registerbox">Email: </div><div id="registeremailtxt" class="registerbox"> <input type="text" name="registeremailtxtbox"></div> <div id="registerconfirmemail" class="registerbox">Confirm Email: </div><div id="registerconfirmemailtxt" class="registerbox"> <input type="text" name="registerconfirmemailtxtbox"></div> <div id="registerpassword" class="registerbox">Password: </div><div id="registerpasswordtxt" class="registerbox"> <input type="text" name="registerpasswordtxtbox"></div> <div id="registerconfirmpassword" class="registerbox"> Confirm Password: </div><div id="registerconfirmpasswordtxt" class="registerbox"> <input type="text" name="registerconfirmpasswordtxtbox"></div> <div id="registerbutton" onClick="regiser()"> Register</div> <div id="registerback" onClick="backlogin()> Back </div>';


} else if(typ=="loggedin"){

changearea.innterHTML = '<div id="loggedin"> Thankyou for logging in - Click to close </div>';

}

}

function gobackwelcome(){
goback();
document.getElementById("welcomemain").innerHTML = '<div id="welcomecontent"><img src="galleryicons/oldwelcome.jpg"></div> ';
}


function playplaylist(){

	if(customplaylist == true){
	//viewmenucreative(0, 0);
		if(viewedsection == "custom"){}
		else{
			viewmenucreative(0, 0);
		}
	} else{
				
	//
	//viewgallerycreative(currentlylookingat);	
	}
	updateplaylist();
	//addedbefore = true;
	moveupcontrol(0, 10);
	minimisemenubottom();
	//hideplaylist();
	moveleftplaylist();



}

function stopplaylist(){
	moverightplaylist();
	maximisemenubottom();
	document.getElementById("control").style.bottom = "-50px";
}

function clearplaylist(){

	if(customplaylist == true){
		playlistcreatives.length = 0
		updateplaylist();} else{
		document.getElementById("playlist").innerHTML = "";
	}
}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

function showleftcontent(elem){
//sets all to same
	document.getElementById("leftwelcomenav").className = "leftwelcomeunselected";
    document.getElementById("leftwelcomecustom").className = "leftwelcomeunselected";
    document.getElementById("leftwelcomeplay").className = "leftwelcomeunselected";
    document.getElementById("leftwelcomesettings").className = "leftwelcomeunselected";
    document.getElementById("leftwelcomenavcontent").style.display = "none";
   	document.getElementById("leftwelcomecustomcontent").style.display = "none";
    document.getElementById("leftwelcomeplaycontent").style.display = "none";
    document.getElementById("leftwelcomesettingscontent").style.display = "none";
	
	document.getElementById("leftwelcome"+elem).className = "leftwelcomeselected";
	document.getElementById("leftwelcome"+elem+"content").style.display="block";


}


var xmlhttp;
function loadXMLDoc(action)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  action1 = action;
  //OLD
  //playlistids = playlistcreatives.join();
  //
  var newplaylist = new Array();
  for(i=0;i<playlistcreatives.length;i++){
  newplaylist[i] = allgallerycreatives[playlistcreatives[i]][10];
  //alert(newplaylist[i]);
  }
  playlistids = newplaylist.join();
  playlistids = ","+playlistids;
//alert(playlistids);
  if (action=="saveplaylist"){
    name = document.getElementById('playlistid').value;
    url = "newgallery/billytest.phtml?ids="+playlistids+"&name="+name;
	xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
  else if (action=="loadplaylist"){
    name = gup('viewplaylist');
    url = "newgallery/billytest2.phtml?playlistkey="+name;
	xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
  else if (action=="sendemail"){
  //Send the proper header information along with the request
  /*
 	  var toname = document.getElementsByName("theirname")[0];
  	  var toaddress = document.getElementsByName("theiremail")[0];
	  var yourname = document.getElementsByName("yourname")[0];
	  var youraddress = document.getElementsByName("youremail")[0];
	  var additional = document.getElementsByName("additionalcontent")[0];
		var elem = document.getElementById("playlistid").innerHTML;
  	var message="Hi "+toname+"Ive been looking through the DoubleClick Rich Media Ad Gallery and found a selection of adverts I thought you would like to see, Ive added them into a custom playlist that Ive shared with you. Click on the link below to see them. http://innovation.doubleclick.net/?viewplaylist="+elem+"<br>"+additional;
  	var subject="DoubleClick Rich Media Ad Gallery";
  	url2="http://ad.uk.tangozebra.com/autoscripts/galleryplaylist/tz_email.phtml";
	//url="http://innovation.doubleclick/newgallery/billytest2.phtml";
	
	xmlhttp.open("POST",url2,true);
	xmlhttp.onreadystatechange=state_Change;
	params = "to_name="+toname+"&from_name="+fromname+"&from_address="+fromaddress+"&toaddress"+toaddress+"&playlist_link"+playlistlink+"&subject="+subject;
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
  	xmlhttp.send(params);*/
	}

  
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}
 
function state_Change()
{
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
    if (action1=="saveplaylist"){
	
	//
	
	var myplaylistis = xmlhttp.responseText;
	var firstchar = myplaylistis.indexOf("Playlist id") + 13;
	var lastchar = myplaylistis.indexOf("</body>");
	var myplaylistis = myplaylistis.substring(firstchar, lastchar);
	//myplaylistis = "fake,"+myplaylistis;
	//alert(myplaylistis);
	
		//alert(xmlhttp.responseText);
      document.getElementById('playlistid').innerHTML=myplaylistis;
	  document.getElementById('playlistlink').innerHTML="http://innovation.doubleclick.net/index.phtml?viewplaylist="+myplaylistis;
	 // document.getElementsByName('playlisttextbox')[0].innerHTML="http://innovation.doubleclick.net/index.html?viewplaylist="+myplaylistis;
	  
    }
    else if (action1=="loadplaylist"){
      playlistids = xmlhttp.responseText;
      lastcoma = playlistids.lastIndexOf(',');
	  
      tempplaylistcreatives = playlistids.substring(0,lastcoma).split(",");
	  
	  var totalinplaylist = 0;
	  for(i=0; i <tempplaylistcreatives.length;i++){
	  	for(j=0; j<allgallerycreatives.length;j++){
		//alert(allgallerycreatives[j][10]);
		//alert(tempplaylistcreatives[i]);
			if(allgallerycreatives[j][10] == tempplaylistcreatives[i]){
			playlistcreatives[totalinplaylist]=j;
			//alert(j);
			totalinplaylist++;
			}
		}	  
	  }
      
	  customplaylist = true;
	  updateplaylist();
	  showplaylist();
	  viewmenucreative(0, 0);
	  
	  
	  //alert(playlistArray);
    } else if(action1=="sendemail"){
	//Sent Email
		document.getElementById("contentwhite").innerHTML = "Email Sent";
	
	}
	
    }
  else
    {
    alert("Problem retrieving data:" + xmlhttp.statusText);
    }
  }
}

playlistArray = new Array();
playlistArray[0] = '5654667';
playlistArray[1] = '575676887';
playlistArray[2] = '77903223'; 


function emailplaylistto(place){

		var toname = document.getElementsByName("theirname")[0].value;
  	  var toaddress = document.getElementsByName("theiraddress")[0].value;
	  var fromname = document.getElementsByName("yourname")[0].value;
	  var fromaddress = document.getElementsByName("youremail")[0].value;
	  var additional = document.getElementsByName("additionalcontent")[0].value;
		var elem = document.getElementById("playlistid").innerHTML;
		
	if(typeof(place) == "string"){
		
			var message = "I've been looking through the DoubleClick Rich Media Ad Gallery and found a selection of adverts I thought you would like to see, I've added them into a section playlist that Ive shared with you. Click on the link below to see them. ";
			var weblink = "http://innovation.doubleclick.net/index.phtml?viewsectionplaylist="+elem;
		
		  	//var message="Hi "+toname+" \n Ive been looking through the DoubleClick Rich Media Ad Gallery and found a selection of adverts I thought you would like to see, Ive added them into a custom playlist that Ive shared with you. Click on the link below to see them. \n http://innovation.doubleclick.net/index.html?viewsectionplaylist="+elem+" \n "+additional;
		}else{
			
			var message = "I've been looking through the DoubleClick Rich Media Ad Gallery and found a selection of adverts I thought you would like to see, I've added them into a custom playlist that Ive shared with you. Click on the link below to see them.";
			var weblink = "http://innovation.doubleclick.net/index.phtml?viewplaylist="+elem;
			
  	//var message="Hi "+toname+" \n Ive been looking through the DoubleClick Rich Media Ad Gallery and found a selection of adverts I thought you would like to see, Ive added them into a custom playlist that Ive shared with you. Click on the link below to see them. \n http://innovation.doubleclick.net/index.html?viewplaylist="+elem+" \n "+additional;
	}
  	var subject="DoubleClick Rich Media Ad Gallery";
  	url2="http://ad.uk.tangozebra.com/autoscripts/galleryplaylist/tz_email.phtml?to_name="+toname+"&from_name="+fromname+"&from_address="+fromaddress+"&to_address="+toaddress+"&playlist_link="+elem+"&subject="+subject+"&message="+message+"&addtional_message="+additional+"&url_link="+weblink;
	//url="http://innovation.doubleclick/newgallery/billytest2.phtml";
	//params = "to_name="+toname+"&from_name="+fromname+"&from_address="+fromaddress+"&toaddress"+toaddress+"&playlist_link"+playlistlink+"&subject="+subject;
	ifrm = document.createElement("iframe");
	ifrm.setAttribute("name", "iframeemailtemp");
	ifrm.setAttribute("id", "iframeemailtemp");
	ifrm.setAttribute("src", url2);
	ifrm.style.width.value = "1px";
	ifrm.style.height.value = "1px";
	ifrm.style.display = "none";
	document.body.appendChild(ifrm);
	document.getElementById("contentwhite").innerHTML = "<div id='closebtn' onclick='closelightbox()'><img src='galleryicons/close26.gif'/></div><div id='emailsentcontainer'><div id='emailsent'>Your email has been sent<br><br><a href='javascript:closelightbox()'>Close</a></div></div>";	
	//document.getElementById("emailsentcontainer").setAttribute("onclick", "closelightbox()");
	//	document.getElementById("emailsentcontainer").onclick = function() {closelightbox()};
	var newdiv = document.createElement("div");
	newdiv.setAttribute("id", "closebtn");
	newdiv.id = "closebtn";
	//newdiv.setAttribute("onclick", "closelightbox()");
	//newdiv.onclick = function() {closelightbox()};
	pageTracker._trackPageview("Emailed Playlist");
}

function emailcreativeto(elem){

	var toname = document.getElementsByName("theirname")[0].value;
  	  var toaddress = document.getElementsByName("theiraddress")[0].value;
	  var fromname = document.getElementsByName("yourname")[0].value;
	  var fromaddress = document.getElementsByName("youremail")[0].value;
	  var additional = document.getElementsByName("additionalcontent")[0].value;
		//var elem = document.getElementById("creativeid").innerHTML;
  	//var message="Hi "+toname+"\n, I've just found this advert in the DoubleClick Rich Media Ad Gallery and I thought it might interest you. Click on the link below to see it. \n http://innovation.doubleclick.net/index.html?viewcreative="+elem+" \n "+additional;
	
	var message = "I've just found this advert in the DoubleClick Rich Media Ad Gallery and I thought it might interest you. Click on the link below to see it.";
	var weblink = "http://innovation.doubleclick.net/index.phtml?viewcreative="+elem;
	
	
  	var subject="DoubleClick Rich Media Ad Gallery";
  	url2="http://ad.uk.tangozebra.com/autoscripts/galleryplaylist/tz_email.phtml?to_name="+toname+"&from_name="+fromname+"&from_address="+fromaddress+"&to_address="+toaddress+"&playlist_link="+elem+"&subject="+subject+"&message="+message+"&addtional_message="+additional+"&url_link="+weblink;
	//url="http://innovation.doubleclick/newgallery/billytest2.phtml";
	//params = "to_name="+toname+"&from_name="+fromname+"&from_address="+fromaddress+"&toaddress"+toaddress+"&playlist_link"+playlistlink+"&subject="+subject;
	ifrm = document.createElement("iframe");
	ifrm.setAttribute("name", "iframeemailtemp");
	ifrm.setAttribute("id", "iframeemailtemp");
	ifrm.setAttribute("src", url2);
	ifrm.style.width.value = "1px";
	ifrm.style.height.value = "1px";
	ifrm.style.display = "none";
	document.body.appendChild(ifrm);	
	<!-- document.getElementById("contentwhite").innerHTML = "<div id='emailsentcontainer'><div id='emailsent'>Email Sent<br><br> Click to Close</div></div>";	 -->
	document.getElementById("contentwhite").innerHTML = "<div id='closebtn' onclick='closelightbox()'><img src='galleryicons/close26.gif'/></div><div id='emailsentcontainer'><div id='emailsent'>Your email has been sent<br><br><a href='javascript:closelightbox()'>Close</a></div></div>";	
	//document.getElementById("emailsentcontainer").setAttribute("onclick", "closelightbox()");
	//document.getElementById("emailsentcontainer").onclick = function() {closelightbox()};
	var newdiv = document.createElement("div");
	newdiv.setAttribute("id", "closebtn");
	newdiv.id = "closebtn";
	//newdiv.setAttribute("onclick", "closelightbox()");
	//newdiv.onclick = function() {closelightbox()};
	pageTracker._trackPageview("Emailed Creative");
}

function termsandconditions(){
	
	document.getElementById("welcomemain").innerHTML = document.getElementById("ToC").innerHTML;
	document.getElementById("welcometitletext").innerHTML = "Terms & Conditions";
	var currentcontent = document.getElementById("pagecontent");
    //document.getElementById("pagecontent").style.zIndex = "201";
   // opacity("pagecontent", 0,100,1);
	
	document.getElementById("welcome").style.zIndex = "260";
	document.getElementById("welcome").style.display = "block";
	resizewelcomecheck();
	/* OLD
var currentframe = document.getElementById("iframecontent");
currentframe.src = "terms.html";
var currentcontent = document.getElementById("pagecontent");
    document.getElementById("pagecontent").style.zIndex = "250";
    opacity("pagecontent", 0,100,1);
	
	document.getElementById("welcome").style.zIndex = "201"; */
	pageTracker._trackPageview("Viewed Terms&Conditions");

}

function resizewelcomecheck(){
	//alert("hi");

var elem = document.getElementById("welcome");
//alert(elem.style.marginLeft);
if(elem.offsetLeft < 197 || elem.style.marginLeft == "0pt" || elem.style.marginLeft == "0px"){
elem.style.left = "207px";
elem.style.marginLeft = "0";
} else{
elem.style.left = "0px";
elem.style.marginLeft = "10%";

}
if(elem.offsetTop < 155 || elem.style.marginTop == "0pt" || elem.style.marginTop == "0px"){
elem.style.top = "160px";
elem.style.marginTop = "0";
} else{
elem.style.top = "0px";
elem.style.marginTop = "10%";
if(BrowserDetect.browser == "Chrome" | BrowserDetect.browser == "Safari"){
	elem.style.marginTop = "20%";
}
}

//Check if more right / bottom

//alert(windowSize().width);
if(windowSize().width <= elem.offsetWidth+elem.offsetLeft || elem.offsetWidth == (windowSize().width - elem.offsetLeft) - 20){
elem.style.width = (windowSize().width - elem.offsetLeft) - 20 + "px";
} else {
	elem.style.width = "";
}

if(windowSize().height <= elem.offsetHeight+elem.offsetTop || elem.offsetHeight == (windowSize().height - elem.offsetTop) - 20){
elem.style.height = (windowSize().height - elem.offsetTop) - 20 + "px";
} else {
	elem.style.height = "";
}

if(document.getElementById("welcomemain") && elem != null){
var elem2 = document.getElementById("welcomemain");
if(elem.offsetHeight > 60){
elem2.style.height = elem.offsetHeight - 60 + "px";
elem2.style.width = elem.offsetWidth - 30 + "px";
}
}

//document.getElementById("mainmenu").style.width = windowSize().width - ((windowSize().width/100)*7) + "px";

if(BrowserDetect.browser == "MSIE" | BrowserDetect.browser == "Explorer"){

//document.getElementById("mainmenu").style.width = "110%";
//if(windowSize().width - ((windowSize().width/100)*7) > 
document.getElementById("mainmenu").style.width = document.getElementById("menu").offsetWidth - ((document.getElementById("menu").offsetWidth/100)*6.3) + "px";

}

}


function moveleftplaylist(){
document.getElementById("playlistcontainer").style.left = "-177px";
document.getElementById("playlist").style.display = "none";
document.getElementById("playlistheader").style.display = "none";
document.getElementById("control2").style.display = "none";
document.getElementById("leftplaylist").setAttribute("onclick", "moverightplaylist()");
document.getElementById("leftplaylist").onclick = function(){moverightplaylist()};

document.getElementById("leftplaylist").innerHTML = "<img src='galleryicons/right_arrow.gif'>";
}

function moverightplaylist(){

document.getElementById("playlistcontainer").style.left = "0px";
document.getElementById("playlist").style.display = "block";
document.getElementById("playlistheader").style.display = "block";
document.getElementById("control2").style.display = "block";
document.getElementById("leftplaylist").setAttribute("onclick", "moveleftplaylist()");
document.getElementById("leftplaylist").onclick = function(){moveleftplaylist()};
document.getElementById("leftplaylist").innerHTML = "<img src='galleryicons/left_arrow.gif'>";
}


function showlatestnews(){
//To Write
	document.getElementById("welcometitletext").innerHTML = "Latest News";
	document.getElementById("welcomemain").innerHTML = document.getElementById("latestsection").innerHTML;
	document.getElementById("welcome").style.zIndex = "260";
	document.getElementById("welcome").style.display = "block";
	resizewelcomecheck();
	currentselsection = "latestnews";
}

function showlatest(){
//To Write	
	document.getElementById("welcometitletext").innerHTML = "Latest News";
	document.getElementById("welcomemain").innerHTML = document.getElementById("latestsection").innerHTML;
	document.getElementById("welcome").style.zIndex = "260";
	document.getElementById("welcome").style.display = "block";
	resizewelcomecheck();
	currentselsection = "latestnews";
	
	
	
}

function showhelpmenu(){
//To Write

}



function setplaylistheight(){
	var elem = document.getElementById("playlist");
	elem.style.top = document.getElementById("menucontainer").offsetTop  + 124 + 28 + 4 + "px";
	//elem.style.top = "0px";
	elem.style.height = (windowSize().height - 28 - (document.getElementById("menucontainer").offsetTop) - 129) - 28 - 4 + "px"; 
}

function refreshiframe(){
	//alert(document.getElementById('iframecontent').href);
//document.getElementById('iframecontent').src = document.getElementById('iframecontent').src;
			if(document.getElementById("playlistcontainer").offsetLeft == "0"){ //Out
            viewgallerycreative(currentselcreative);
			}else{
				viewgallerycreative(currentselcreative);
				moveleftplaylist()
			}
//frames['iframecontent'].location.reload(1);
}

