var moeffectp=1;
var moeffectv=1;

function pclick(i,n)
{
	for(j=1;j<=n;j++)
	{
		na="document.pic"+j;
		eval(na).src="../images/photo-"+j+"b.gif";
		eval(na).style.cursor="none";	
	}
	a="document.pic"+i;
	eval(a).src="../images/photo-"+i+"a.gif";
	moeffectp=0;
	document.getElementById("npics").value=i;
}
function vclick(i,n)
{
	for(j=1;j<=n;j++)
	{
		na="document.vid"+j;
		eval(na).src="../images/video-"+j+"b.gif";
		eval(na).style.cursor="none";	
	}
	a="document.vid"+i;
	eval(a).src="../images/video-"+i+"a.gif";
	moeffectv=0;
	document.getElementById("nvids").value=i;
}
function mouseover(i,j)
{
	if(moeffectp == 1)
	i.src="../images/photo-"+j+"a.gif";
}
function mouseout(i,j)
{
	 if(moeffectp == 1)
	 i.src="../images/photo-"+j+".gif";
}
function mouseover1(i,j)
{
	if(moeffectv == 1)
	i.src="../images/video-"+j+"a.gif";
}
function mouseout1(i,j)
{
	 if(moeffectv == 1)
	 i.src="../images/video-"+j+".gif";
}

function savecoord()
{
	document.Form1.TextBox1.value=document.body.scrollTop;
}
function scroll()
{
	document.body.scrollTop=document.Form1.TextBox1.value;	
}	
function valcategory()
{
	args.IsValid = false;
}
function display(i)
{
	window.open("contest-detail.aspx?id="+i,'win3','toolbar=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes');
	//window.location.href="contest-detail.aspx?id="+i;
}

function displayR2(i)
{
	window.open("contest-detailR2.aspx?id="+i,'win4','toolbar=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes');
	//window.location.href="contest-detail.aspx?id="+i;
}
function displayR3(i)
{
	window.open("contest-detailR3.aspx?id="+i,'win5','toolbar=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes');
	//window.location.href="contest-detail.aspx?id="+i;
}

/*Image Slide Show*/

function startslide(i,j)
{
	//alert(i,j);
	window.open("contest-slideshow.aspx?cat="+i+"&start="+j,'win1','toolbar=no,scrollbars=no,resizable=yes');
}

function startslideR2(i,j)
{
	//alert(i,j);
	window.open("contest-slideshowR2.aspx?cat="+i+"&start="+j,'win2','toolbar=no,scrollbars=no,resizable=yes');
}

function startslideR3(i,j)
{
	//alert(i,j);
	window.open("contest-slideshowR3.aspx?cat="+i+"&start="+j,'win2','toolbar=no,scrollbars=no,resizable=yes');
}

var imgarray,arrwidth,arrheight,arrtitle,arrids,arrviews,arrranks,arrcomments;
var vis=100;
var imgno=0;
var lhigh,hhigh;
var running=1;
var move=1;
var newimg;
var sleep=0;
var loading;
var currclick=0;
var thread1,thread2;

//initialize the thread
function getimglist(str)
{	
	imgarray=str.split(",");
	newimg=new Image();
	newimg.src="../contest-images/lg"+imgarray[0];
	document.main.src=newimg.src;
	document.getElementById('cell0').style.borderColor='#ff6600';
	document.getElementById("titles").innerHTML="<font style='font-size:12px;font-family:verdana;font-weight:bold'>"+arrtitle[0]+"</font>";
	document.getElementById("imgcount").innerHTML="Image <strong>1</strong> of "+imgarray.length;
	document.getElementById("desc").innerHTML="<font style='color:#ffffff;cursor:pointer;text-decoration:underline' onclick='display("+arrids[0]+");'>View Description</font>";
	document.getElementById("comments").innerHTML="<font style='color:#ffffff;cursor:pointer;text-decoration:underline' onclick='display("+arrids[0]+");'>Add Comment</font>";
	if(imgarray.length>1)
	setsize();
}
function setwidth(imgwidth)
{
	arrwidth=imgwidth.split(",");
}
function setheight(imgheight)
{
	arrheight=imgheight.split(",");
}
function settitle(imgtitle)
{
	arrtitle=imgtitle.split("#");
	for(t=0;t<arrtitle.length-1;t++)
		arrtitle[t]=arrtitle[t].replace("_","''");
}	
function setothers(imgids,imgviews,imgranks,imgcomments)
{
	arrids=imgids.split(",");
	arrviews=imgviews.split(",");
	arrranks=imgranks.split(",");
	for(arruse=0;arruse<arrranks.length;arruse++)
	if(arrranks[arruse] == '' || arrranks[arruse] == '0')
			arrranks[arruse]='NA';
	arrcomments=imgcomments.split(",");	
}	

//change image
function chimg()
{
	if(imgno < imgarray.length-1)
		imgno=imgno+1;
	else
		imgno=0;
	newimg=new Image();
	newimg.src="../contest-images/lg"+imgarray[imgno];	
	document.main.src=newimg.src;
	for(cells=0;cells<imgarray.length;cells++)
	{
		cellno="document.getElementById('cell"+cells+"')";
		eval(cellno).style.borderColor='#eeeeee';
	}
	cellno="document.getElementById('cell"+imgno+"')";
	eval(cellno).style.borderColor='#ff6600';
	setsize();	
}

//set size and other details that vary with every image also if the slider needs to move
function setsize()
{
	document.main.width=arrwidth[imgno];
	document.main.height=arrheight[imgno];	
	//change other details
	document.getElementById("titles").innerHTML="<font style='font-size:12px;font-family:verdana;font-weight:bold'>"+arrtitle[imgno]+"</font>";
	document.getElementById("imgcount").innerHTML="<font style='background-color:#aeb2ac;color:#000000'>Image <strong>"+eval(parseInt(imgno)+1)+"</strong> of "+imgarray.length+"</font>";
	document.getElementById("desc").innerHTML="<font style='color:#ffffff;cursor:pointer;text-decoration:underline' onclick='display("+arrids[imgno]+");'>View Description</font>";
	document.getElementById("comments").innerHTML="<font style='color:#ffffff;cursor:pointer;text-decoration:underline' onclick='display("+arrids[imgno]+");'>Add Comment</font>";
	if(document.getElementById("details").innerHTML != "")
	document.getElementById("details").innerHTML="By: "+arrranks[imgno]+"<br>On: "+arrviews[imgno]+"<br>Comments: "+arrcomments[imgno]+"";
	
	//if its been more than 15 secs any of the arrows was clicked, move the slider as required
	if(move == 1)
	{
		lhigh=eval(parseInt(imgno+1)*90 - (Math.abs(parseInt(document.getElementById('scroller').style.left))));
		hhigh=eval(parseInt(imgno+1)*90 - (Math.abs(parseInt(document.getElementById('scroller').style.left))+900));
		
		if(lhigh < 0)
		{
			document.getElementById('scroller').style.left=eval((-(parseInt(imgno+1)*90))+120);
		}
		if(hhigh > 0)
		{
			document.getElementById('scroller').style.left=eval((-(parseInt(imgno+1)*90))+540);
		}
	}
	vis=0;
	fadein();
}

//current image fading out
function fadeout()
{
	currclick = 0;
	if(sleep == 1)
	{
		setTimeout("restart()",8000);
	}
	else
	{
	if(running)
	{
		if(vis >= 0)
		{
			vis=vis-5;
			document.main.style.filter="alpha(Opacity="+vis+")";
			setTimeout("fadeout()",10);
		}
		else
		{
			document.getElementById("mainbg").style.backgroundImage ="url(../images/loading.gif)";
			document.getElementById("mainbg").style.backgroundRepeat="no-repeat";
			document.getElementById("mainbg").style.backgroundPosition="center";
			thread2=setTimeout("chimg()",50);
		}
	}
	}
}

//current image fading in
function fadein()
{
	if(newimg.complete)
	{
		if(vis <= 100)
		{
			vis=vis+5;
			document.main.style.filter="alpha(Opacity="+vis+")";
			setTimeout("fadein()",5);
		}
		else
		{
			document.getElementById("mainbg").style.background="none";
			thread1=setTimeout("fadeout()",8000);
		}
	}
	else
	{
		//document.main.style.filter="alpha(Opacity=0)";	
		if(currclick == 0)
		{
		setTimeout("fadein()",10);
		}
	}
}

//if the border is to be removed on mouseout
function chkcell(cl)
{
	if(cl == imgno)
		return true;
	else
		return false;	
}

//move slider right
function moveright()
{
	pos=document.getElementById('scroller').style.left;
	pos=pos.substring(0,pos.length-2);
	if(pos > -(imgarray.length*90-850))
	{
	document.getElementById('scroller').style.left=pos-50;
	}
	move=0;
	setTimeout("moveres()",20000);
}

//move slider left
function moveleft()
{
	pos=document.getElementById('scroller').style.left;
	pos=pos.substring(0,pos.length-2);
	if(pos < 30)
	document.getElementById('scroller').style.left=pos-(-50);
	move=0;
	setTimeout("moveres()",20000);
}	

//show rank,views,comments
function showdets()
{
	if(document.getElementById("details").innerHTML != "")
	{
		document.getElementById("details").innerHTML="";
		document.getElementById("toggle").innerHTML="<font style=cursor:pointer onclick='showdets();'>+</font>";
	}
	else
	{
		document.getElementById("details").innerHTML="By: "+arrranks[imgno]+"<br>On: "+arrviews[imgno]+"<br>Comments: "+arrcomments[imgno]+"";
		document.getElementById("toggle").innerHTML="<font style=cursor:pointer onclick='showdets();'>-</font>";
	}
}

//reset the slider
function moveres()
{
	move=1;
}

//change the current image to clicked one
function currimg(img1)
{
	currclick = 1;
	document.main.style.filter="alpha(Opacity=0)";	
	newimg=new Image();
	newimg.src="../contest-images/lg"+imgarray[img1];
	document.main.src=newimg.src;
	document.getElementById("mainbg").style.backgroundImage ="url(../images/loading.gif)";
	document.getElementById("mainbg").style.backgroundRepeat="no-repeat";
	document.getElementById("mainbg").style.backgroundPosition="center";
	document.main.width=arrwidth[img1];
	document.main.height=arrheight[img1];
	document.main.style.filter="alpha(Opacity=100)";
	document.getElementById("titles").innerHTML="<font style='font-size:12px;font-family:verdana;font-weight:bold'>"+arrtitle[img1]+"</font>";
	document.getElementById("imgcount").innerHTML="<font style='background-color:#aeb2ac;color:#000000'>Image <strong>"+eval(parseInt(img1)+1)+"</strong> of "+imgarray.length+"</font>";
	for(cells=0;cells<imgarray.length;cells++)
	{
		cellno="document.getElementById('cell"+cells+"')";
		eval(cellno).style.borderColor='#eeeeee';
	}
	cellno="document.getElementById('cell"+img1+"')";
	eval(cellno).style.borderColor='#ff6600';
	document.getElementById("desc").innerHTML="<font style='color:#ffffff;cursor:pointer;text-decoration:underline' onclick='display("+arrids[img1]+");'>View Description</font>";
	document.getElementById("comments").innerHTML="<font style='color:#ffffff;cursor:pointer;text-decoration:underline' onclick='display("+arrids[img1]+");'>Add Comment</font>";
	if(document.getElementById("details").innerHTML != "")
	document.getElementById("details").innerHTML="By: "+arrranks[img1]+"<br>On: "+arrviews[img1]+"<br>Comments: "+arrcomments[img1]+"";
	imgno=parseInt(img1);	
	sleep=1;	
}

//toggle playing and stopping the slideshow
function stopslide()
{
	if(running != 0)
	{
		document.getElementById("togglebut").src="../images/continue.jpg";
		if(thread2)
			clearTimeout(thread2);
		if(thread1)	
		clearTimeout(thread1);
		running=0;		
	}
	else
	{
		document.getElementById("togglebut").src="../images/pause.jpg";
		running=1;
		fadeout();
	}
}

//previous image
function previmg()
{
	if(imgno==0)
		imgno=imgarray.length-1;
	else	
		imgno=imgno-1;
	currimg(imgno);
}

//next image
function nxtimg()
{
	if(imgno==imgarray.length-1)
		imgno=0;
	else	
		imgno=imgno+1;
	currimg(imgno);	
}

function restart()
{
	sleep=0;
	fadeout();
}
function RefreshParent(i)
{
	window.parent.location.href = i;
}

function showrounds()
{
	
	if(document.getElementById("toggle").innerHTML == "")
	{
	var text="<TABLE id='details' cellSpacing='0' cellPadding='0' width='100%' border='0'>";
	text=text+"<tr><TD style='PADDING-BOTTOM: 15px; LINE-HEIGHT: 17px' vAlign='top'><STRONG style='FONT-SIZE: 12px; COLOR: #ff6600'>";
	text=text+"Round 1 </STRONG><BR><STRONG style='COLOR: #ff6600'>&raquo; </STRONG>Members can 'Vote Out' an image by ";
	text=text+"assigning Negative (-ve) votes to that picture till the submission for new entrees is not over <STRONG style='COLOR: #ff6600'>&raquo; </STRONG>A member can vote ";
	text=text+"only once <STRONG style='COLOR: #ff6600'>&raquo; </STRONG>The maximum number of -ve votes ensure that an entry won't qualify for Round 2, alternately an entry with ";
	text=text+"maximum number of +ve votes will enter Round- II <STRONG style='COLOR: #ff6600'>&raquo; </STRONG>The top 100* photos from each category will qualify for Round 2 on the basis of ";
	text=text+"total number of +ve Votes received.</TD></TR><TR><TD style='PADDING-BOTTOM: 15px; LINE-HEIGHT: 17px' vAlign='top'><STRONG style='FONT-SIZE: 12px; COLOR: #ff6600; LINE-HEIGHT: 17px'>Round ";
	text=text+"2 </STRONG><BR><STRONG style='COLOR: #ff6600'>&raquo; </STRONG> Here members can 'Vote In' and 'Rank' the pictures that have made it to Round 2. <STRONG style='COLOR: #ff6600'>&raquo; </STRONG>";
	text=text+"Once the cut off date to 'Vote' and 'Rank' is over, top 50* pictures from each category will be selected on the basis of <B>Members' Choice Score</B>, which will be <B>";
	text=text+"the product of Total Number of Votes Received</B> &amp; <B>the Members' Rank for that entry <SPAN style='COLOR: #006600'><BR>(Members' Choice Score = Votes X Rank)</SPAN></B>";
	text=text+"<P><STRONG style='FONT-SIZE: 12px; COLOR: #ff6600; LINE-HEIGHT: 17px'>Final Stage </STRONG><BR>These pictures (top 50*) will then go to a panel of <A href='contest-judges.aspx'>Expert Judges</A>, ";
	text=text+"who will rate them on a scale of 1-10 (max).<BR><STRONG>The winners (Mega Winners + Winners) will be selected on the basis of Finalist Score.</STRONG></P>";
	text=text+"<P>The<STRONG> Finalist Score</STRONG> will be the<STRONG> product of Members' Choice Score</STRONG> &amp; <STRONG>Judge's Rating</STRONG><BR><STRONG style='COLOR: #006600'>";
	text=text+"(Finalist Score= Members' Choice Score X Judges' Rating)</STRONG>.</P><P>On the basis of <STRONG>Finalist Score, the top 10 Finalist</STRONG> will be selected<BR>and out of these the <STRONG>";
	text=text+"Top 3 from each category will be the Mega Winners</STRONG></P></TD></TR></TABLE>";
	document.getElementById("toggle").innerHTML=text;
	document.getElementById("toggletext").innerHTML="HIDE DETAILS";
	}
	else
	{
	document.getElementById("toggle").innerHTML="";
	document.getElementById("toggletext").innerHTML="SEE DETAILS";
	}
}

function txtfocus()
{
	alert();
	document.Form1.question.focus();
}

function prizes()
{
	window.location.href="contest-flowdetail.aspx#prizes";
}