var ominCountSet = true;
var currentPhoto = 0;
var firstimg=0;
var secondPhoto = 1;
var frmclick=false;
var currentOpacity = new Array(); 
var bundleColl=new Array();
var imageArray = new Array();
var selectedObj="";
var FADE_STEP = 3; // default 1
var FADE_INTERVAL = 1; //default 20
var pause = false;
var chgHTML="";
var browser = "";
var mInterval = "";
var xInterval = "";
var click_count = [0,0,0,0]; // Each 0 represent each thumbnail.
var version = navigator.appVersion.substr(0,navigator.appVersion.indexOf(" ("));

		if(navigator.appName=="Microsoft Internet Explorer"){
			browser="IE";
		}else if(navigator.appName=="Netscape"){
			browser="NS";
		}
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 
			var ieversion=new Number(RegExp.$1);
		
		}
		function getkeywords() {
		
		var x = document.referrer;
			if(x == ""|| x=="null"){
						return x;
				}
				else{

					
					var strReplace = "+";
					x = x.replace(strReplace," ");

					return x; 
				}
		}

//To compare the search key words with the given keywords in the each campaign 

		function CompareSearchKey()	{
		
			var keyword = getkeywords();
			var uls = document.getElementsByTagName("ul");			
			var ulx, l, c;
			for (var ulxs=0; ulxs<uls.length; ulxs++){			
				ulx = uls[ulxs];
				for (var lis=0; lis<ulx.childNodes.length; lis++){				
					l=ulx.childNodes[lis];					
					if (l.nodeType==1){					
						c=trim(l.innerHTML);					
						keyword = keyword.replace('+', ' ');
						if(keyword.indexOf(c)>0){		
							return(ulxs);
						}
					}
				}
			}			
			return 0;
			// to make the default image or to start from the second image otherwise return0.
		}
//function trim() -- to remove the white space from the end of search string. To solve the IE6 and IE7 issue.
		function trim(stringToTrim) {

				return stringToTrim.replace(/^\s+|\s+$/g,"");
		}
		
		function start(){
		
				var contentDiv = document.getElementById("campaing");
				var div = contentDiv.getElementsByTagName("div");
				for ( var j = 0; j < div.length; j++ ) {
							imageArray[j]=div[j].id;
					}
				init();
		}

		function init() { 

				currentOpacity[0]=99;
				for(i=1;i<imageArray.length;i++)
				currentOpacity[i]=0;
				mHTML="";
				chgHTML='<table id="thumbTray"><tbody><tr><td  width="7px"></td>';
						for(i=0;i<imageArray.length;i++){
								var opacity = "";
								if(browser=="IE"){
										opacity = "filter:alpha(opacity="+currentOpacity[i]+")";
					
								} else if(browser=="NS" && version=="5.0"){		
										opacity = "opacity:"+currentOpacity[i];
								} else {
										opacity = "MozOpacity:"+currentOpacity[i];
								}
								
								var img_url = document.getElementById(imageArray[i]).style.backgroundImage;
		img_url=img_url.replace('"','');
		mHTML+="<div id=\"photo\" name=\"photo\" ";
		mHTML+="style=\"z-index:"+(0-i)+";"+opacity+";"; 
		
		mHTML+="background-image:"+img_url+";\">";		
		mHTML+=document.getElementById(imageArray[i]).innerHTML+"</div>";
									

		//mHTML+="<div id=\"photo\" name=\"photo\" style=\"z-index:"+(0-i)+";"+opacity+"; background-image:"+document.getElementById(imageArray[i]).style.backgroundImage+"\";>"+document.getElementById(imageArray[i]).innerHTML+"</div>";

					var imgTrim = document.getElementById(imageArray[i]);
					var imgTrims = "";
					var imgTxt = "";
						if(browser=="IE" && ieversion <=6){ 
								var elem = imgTrim.getElementsByTagName("img");      
								imgTrims = elem[0].getAttribute("src"); 
								imgTxt = imgTrim.getElementsByTagName("span");
								imgTxt = imgTxt[0].innerHTML;

						}
						else if(browser=="IE" && ieversion >6){
								var elem = imgTrim.getElementsByTagName("img");  							
								imgTrims = elem[0].getAttribute("src");        
								elem = imgTrim.getElementsByTagName("span");
								imgTxt = elem[0].innerHTML;
								//imgTxt = imgTrim.getElementsByTagName("span").item(imageArray[i]).innerHTML;
						}
						else{
								imgTrims = imgTrim.getElementsByTagName("img").item(imageArray[i]).src;
								imgTxt = imgTrim.getElementsByTagName("span").item(imageArray[i]).innerHTML;

						}
			
	
var thumb_nail_id = document.getElementById(imageArray[i]).id;

//font-weight:bold;width="95px"
var nxt_nav = '<td name="thumb" id="thumb" class="thumb_nails" width="50px" style="background-position: 0px -46px;background-image:url('+ imgTrims + ');background-repeat:no-repeat;" onClick="changeImage(' + (i) + ',false);thumbnail_click(\'' + thumb_nail_id + '\');" onmouseover="changeColor(this,' + (i) + ')" onmouseout="reverseColor(this,' + i + ')"></td><td id="thumbText" align="left" name="thumbText" style="font-Size:11px;font-family:Arial, Helvetica, sans-serif;padding-top:7px;" onmouseover="changeColor(this.previousSibling,' + i + ')" onmouseout="reverseColor(this.previousSibling,' + i + ')">' + '<a name="aText" id="aText" class="anc" style="color:#D9D9D4;text-decoration: none;text-align:left;font-family:Arial, Helvetica, sans-serif;font-Size:11px;" href="javascript:changeImage(' + (i)  + ',false);thumbnail_click(\'' + thumb_nail_id + '\');">' + imgTxt + '</a>' + '</td>';
		chgHTML += nxt_nav;

				}
			
			chgHTML+="<td align='left' width='0px'></td></tr></tbody></table>";
			
			document.getElementById("imageContainer").innerHTML = mHTML;
			document.getElementById("changer").innerHTML = chgHTML;

				if(browser=="IE"){
						document.getElementsByName("photo")[currentPhoto].style.filter="alpha(opacity=100)";
				}else if(browser=="NS" && version=="5.0"){
						document.getElementsByName("photo")[currentPhoto].style.opacity = .99;
				}else {
						document.getElementsByName("photo")[currentPhoto].style.MozOpacity = .99;
				}
			 
			mInterval = setInterval("crossFade()",FADE_INTERVAL);
			firstimg=CompareSearchKey();
			changeImage(firstimg,true);

		}

		function crossFade() {
		
		var camp_change_id = document.getElementsByTagName("img")[currentPhoto].id; // for omniture tracking
		if(ominCountSet==true)
		{
		 campaing_count(camp_change_id)
		 ominCountSet=false;
		}
		
			if(pause){ 
			
			return;}
		//	var camp_change_id = document.getElementsByTagName("img")[currentPhoto].id; // for omniture tracking

			currentOpacity[currentPhoto]-=FADE_STEP;
			currentOpacity[secondPhoto] += FADE_STEP;
			document.getElementsByName("thumb")[currentPhoto].style.backgroundPosition = '0px -46px';	
			//document.getElementsByName("thumbText")[currentPhoto].style.fontWeight = "normal";
			document.getElementsByName("thumbText")[currentPhoto].style.fontSize = "11px";			
			document.getElementsByName("aText")[currentPhoto].style.color = '#D9D9D4';
			if(frmclick==true)
			{

						document.getElementsByName("thumb")[currentPhoto].style.backgroundPosition = '0px 0px';
						//document.getElementsByName("thumbText")[currentPhoto].style.fontWeight = "bold";						
						document.getElementsByName("thumbText")[currentPhoto].style.fontSize = "11px";
						document.getElementsByName("aText")[currentPhoto].style.color = '#FFFFFF';
						return;
			}
				
			if(document.all) {
				document.getElementsByName("photo")[currentPhoto].style.filter = "alpha(opacity=" + currentOpacity[currentPhoto] + ")";
				document.getElementsByName("photo")[secondPhoto].style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")";
			} else if(browser=="NS" && version=="5.0"){
				document.getElementsByName("photo")[currentPhoto].style.opacity = currentOpacity[currentPhoto]/100;
				document.getElementsByName("photo")[secondPhoto].style.opacity =currentOpacity[secondPhoto]/100;
			}else if(document.navigator == "") {
				document.getElementsByName("photo")[currentPhoto].style.MozOpacity = currentOpacity[currentPhoto]/100;
				document.getElementsByName("photo")[secondPhoto].style.MozOpacity =currentOpacity[secondPhoto]/100;
			}
			
			if(currentOpacity[secondPhoto]/100>=.98) {
				//	ominCountSet = true;
				
				document.getElementsByName("photo")[currentPhoto].style.zIndex=-1;
				currentPhoto = secondPhoto;
				document.getElementsByName("photo")[currentPhoto].style.zIndex=0;		
				secondPhoto++;
				if(secondPhoto == imageArray.length)secondPhoto=0;
				pause = true;

				xInterval = setTimeout("pause=false",6000);					

			}
			
			document.getElementsByName("thumb")[currentPhoto].style.backgroundPosition = '0px 0px';
			//document.getElementsByName("thumbText")[currentPhoto].style.fontWeight = "bold";
			document.getElementsByName("thumbText")[currentPhoto].style.fontSize = "11px";
			document.getElementsByName("aText")[currentPhoto].style.color = '#FFFFFF';

		}
		function currentThumbHigh(current_photo_num)
		{ 		
				click_count[current_photo_num]=click_count[current_photo_num]+1;
				if((firstimg)==current_photo_num && click_count[current_photo_num]>0)
				{
					document.getElementsByName("thumb")[firstimg].style.backgroundPosition = '0px 0px';
					//document.getElementsByName("thumbText")[firstimg].style.fontWeight = "bold";
					document.getElementsByName("thumbText")[firstimg].style.fontSize = "11px";
					document.getElementsByName("aText")[currentPhoto].style.color = '#FFFFFF';
					return true;
				}				
			
		}
		
		function changeImage(num,frminit){
				
			
				currentOpacity[currentPhoto]=0;
				currentOpacity[secondPhoto]=0;
				secondPhoto = parseInt(num);		
				if(secondPhoto == imageArray.length)secondPhoto=0;
					currentOpacity[currentPhoto]=0;
					currentOpacity[secondPhoto]=99;	
					
			document.getElementsByName("thumb")[currentPhoto].style.backgroundPosition = '0px -46px';	
			//document.getElementsByName("thumbText")[currentPhoto].style.fontWeight = "normal";					
			document.getElementsByName("thumbText")[currentPhoto].style.fontSize = "11px";
			document.getElementsByName("aText")[currentPhoto].style.color = '#D9D9D4';
			if(document.all) {
				document.getElementsByName("photo")[currentPhoto].style.filter = "alpha(opacity=0)"; 
				document.getElementsByName("photo")[secondPhoto].style.filter = "alpha(opacity=100)"; 
			} else if(browser=="NS" && version=="5.0"){
				document.getElementsByName("photo")[currentPhoto].style.opacity = 0; 
				
				document.getElementsByName("photo")[secondPhoto].style.opacity = 1; 
				}else if(document.navigator == "") {
				document.getElementsByName("photo")[currentPhoto].style.MozOpacity = 0;
				
				document.getElementsByName("photo")[secondPhoto].style.MozOpacity = 1;
				
			}			

				document.getElementsByName("photo")[currentPhoto].style.zIndex=-1;
				currentPhoto = secondPhoto;
				document.getElementsByName("photo")[currentPhoto].style.zIndex=0;		
				secondPhoto++;
				if(secondPhoto == imageArray.length)secondPhoto=0;

			document.getElementsByName("thumb")[currentPhoto].style.backgroundPosition = '0px 0px';
			//document.getElementsByName("thumbText")[currentPhoto].style.fontWeight = "bold";
			document.getElementsByName("thumbText")[currentPhoto].style.fontSize = "11px";
			document.getElementsByName("aText")[currentPhoto].style.color = '#FFFFFF';
				pause = true;
				clearInterval(xInterval);				
				xInterval = setTimeout("pause=false",4000);		
				if(frminit==false)
				{
					frmclick=true;
var camp_change_id = document.getElementsByTagName("img")[currentPhoto].id; // for omniture tracking			
					campaing_count(camp_change_id)
					return;
				}

			}

		function changeColor(obj,i){ 
				document.body.style.cursor='pointer';
				 if (obj.style.backgroundPosition == '0px 0px'){
						selectedObj = obj;
						return;
				 }
				 
						if ( i != currentPhoto){
						document.getElementsByName("aText")[i].style.color = '#FFFFFF';
						obj.style.backgroundPosition = '0px 0px';
						changeTextToBold(obj.nextSibling);		
						}
		}
		
		function changeTextToBold(obj){
					//obj.style.fontWeight = "bold";
					obj.style.fontSize = "11px";
					//obj.style.color = '#FFFFFF';
					//document.getElementsByName("aText")[obj].style.color = '#FFFFFF';

		}
		
		function changeTextToNormal(obj){
					//obj.style.fontWeight = "normal";
					obj.style.fontSize = "11px";
					//obj.style.color = '#D9D9D4'; 
					//document.getElementsByName("aText")[obj].style.color = '#D9D9D4';
		}
		
		function reverseColor(obj,i){
				document.body.style.cursor='default';	
				if ( i != currentPhoto) {
				document.getElementsByName("aText")[i].style.color = '#D9D9D4';
				obj.style.backgroundPosition = '0px -46px';
				changeTextToNormal(obj.nextSibling); }
		}
		window.addEventListener?window.addEventListener("load",start,false):window.attachEvent("onload",start);
		
//	************************** OMNITURE CODE  [BEGINS] ************************************************//	

 //function campaing_count to track which campaign is currently showing in the frame 
	function campaing_count(camp_ids){

	
	}
		
		
//function learnmore_click for the LearMore link Click 
	function learnmore_click(linkVal){ 

	}
	
// function thumbnail_click is for the ThumbNail and ThumbText Click
	function thumbnail_click(id_thumb){		

		
	}	
	
//	************************** OMNITURE CODE [ENDS] ************************************************//	
