var ContentHeight = 300;
var TimeToSlide = 350.0;
var openAccordion = '';

var previousNid = 0;
var previousCount=0;
var subPrev = '';
var PrevTitle_onskip = '';
var setNid=0;
var flag = false;
var getPreviousVote='';
var p=0;
var StrPre='';
var StrFunny='' ;
var StrThanks='';
var StrSorry='' ;
var StrNF='';
var StrRate='';

function getXMLHTTP()
{
	var xmlHttp=null;
	try
	{
	 	// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();

 	}
	catch (e)
	{
		//Internet Explorer
		 try
		{
	  		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
 		catch (e)
		{
		  	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		if(navigator.userAgent.indexOf("MSIE 6.0"))
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	return xmlHttp;

}


function isdefined( variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function init() 
{

//runAccordion(1);
//changeImage(1);
var x = document.getElementById("aa1");
if(x != undefined)
{
source = x.src;
//alert(source);
var top_arrow_index = source.indexOf("bottom");
arrowstr = source.substr(top_arrow_index,(source.length));
sourcestr = source.substr(0,top_arrow_index);
//alert(sourcestr);
deststr = sourcestr+'top-arrow-grey.gif';	
x.setAttribute("src", deststr);
x.style.display = 'none';
}
document.getElementById("previously").value =  document.getElementById('Finit').value ;
//document.getElementById("jk_title1").innerHTML = document.getElementById("previously").value;
StrPre = document.getElementById("ACstrP").value;
StrFunny =document.getElementById("ACstrFun").value;
StrThanks = document.getElementById("ACstrThanks").value;
StrSorry = document.getElementById("ACstrSorry").value;
StrNF = document.getElementById("ACstrNF").value;
StrRate = document.getElementById("ratethese").value;

 
}

function runAccordion(index1)
{
	

  var nID = "Accordion" + index1 + "Content";
  if(openAccordion == nID)
    nID = '';
    
  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" + openAccordion + "','" + nID + "'," + index1 + ")", 33);
  
  openAccordion = nID;
  
}

function animate(lastTick, timeLeft, closingId, openingId, index2)
{  
//alert("a")
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  //var divid = "Accordion" + index1 + "Content";
  var opening = (openingId == '') ? null : document.getElementById(openingId);
  var closing = (closingId == '') ? null : document.getElementById(closingId);
 // var getTitleDiv = "jk_title" + index2;

 //alert(openingId+">>>>>>"+closingId);

if(index2 != undefined)
{
	setNid = index2;
}

  if(timeLeft <= elapsedTicks)
  {
    if(opening != null)
		opening.style.height = '320px';
	
		p = document.getElementById(setNid).offsetHeight;

		
		var r = document.getElementById('rightContent').offsetHeight;
		var left =  document.getElementById('leftContent').offsetHeight;
		var lc =  document.getElementById('leftContent');

		
		
		var right = document.getElementById('rightContent');
	
		//var ac =  document.getElementById('AccordionContainer').offsetHeight;
		var accCon = 0;
		if(r > left)
			getLargeDiv = r;
		else
			getLargeDiv = left;

        if(setLargeDiv == 'undefined')
			{
				setLargeDiv = getLargeDiv
					//alert("setH"+setLargeDiv);
			}
			 opening.style.height = 'auto';
		//alert("R"+r+","+"L"+left+"Large"+getLargeDiv);

		try
		{
			accCon =  document.getElementById(openingId).offsetHeight;
			//alert("OpenHeight"+accCon);
			if((left + accCon) > getLargeDiv)
			{
				var getDiff = (left + accCon) - getLargeDiv;
				lc.style.height = left + getDiff + "px";
				right.style.height = left + getDiff + "px";
				
				//alert(lc.style.height);

			}
			else
			{
				 lc.style.height = left + 10 + "px";
				  right.style.height = left + 10 + "px";
			}
		}
		catch (Err)
		{
				accCon = 0;
		}
	//alert(p);
	/*var r = document.getElementById('rightContent').offsetHeight;
	var lc =  document.getElementById('leftContent');
	var diff = 605 - p;
	//alert("Ph="+p+"diff="+diff);
	if((p > 200) && (p < 500))
	{
	    // alert("H>200and<500");
		r = document.getElementById('rightContent');
		lc.style.height = 800 + diff+'px';
		r.style.height =  800 + diff+'px';
		
	}
	else if((p >= 500) && (p < 750))
	{
	  //alert("H>500and<750"+p);
		r = document.getElementById('rightContent');
		lc.style.height = 900 + diff+'px';
		r.style.height =  900 + diff+'px';
	}
	else
	{
    	r = document.getElementById('rightContent');
	 	if(r.style.height != 605)
	 	{
	  		var para = document.getElementById(setNid);
	  		r.style.height = 605+'px';
	  		lc.style.height = 605+'px';
	  		para.style.height = p+'px';
	  		//flag = false;
		}
	} */ 
    if(closing != null)
    {
	
    	closing.style.display = 'none';
    	closing.style.height = '0px';
		if((openingId =="") || (closingId==""))
	  	{	 
	   //alert("same") ;
	   if(r.style.height != 605)
	 	{  
		
	  		   var r = document.getElementById('rightContent');
				var lc =  document.getElementById('leftContent');
				 r.style.height = setLargeDiv + 'px';
				 lc.style.height = setLargeDiv + 'px';
		}
	 
	 }
	
    }
	
    return;
  }
 
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);

  if(opening != null)
  {
	
    if(opening.style.display != 'block')
     opening.style.display = 'block';
	 opening.style.height = (ContentHeight - newClosedHeight) + 'px';
	
	
  }
  
  if(closing != null)
  {
  	  closing.style.height = newClosedHeight + 'px';
	 
	
  }
  


  setTimeout("animate(" + curTick + "," + timeLeft +",'" + closingId + "','" + openingId + "')", 33);
}


function Ajax_Carousel(strURL,Int_cnt,Str_basePath,Str_filePath)
{
	//alert(strURL);
//	alert(Int_cnt+","+Str_basePath+","+Str_filePath);
	var SetVotesAtPrevious;var SetVotesAtContent;var getChioceRes3;
	var req = getXMLHTTP();
	

//	alert(req);
	if(req)
	{
		req.onreadystatechange = function()
		{
			if(req.readyState == 4)
			{ 
				if (req.status == 200)
				{	
					var AjaxStr = req.responseText;
					//alert(AjaxStr);
					
				   var getContent = document.getElementById('from_ajax');
				   
				   getContent.innerHTML = AjaxStr;  changeImage(Int_cnt); runAccordion(Int_cnt);
				   
				}
				
			}
			
		}
		
		//
		req.open("GET", strURL, true); //open url using get method
	    req.send(null);	
		
	}
	
}
function showvote()
{}

function Ajax_call(strURL,Int_cnt,Str_basePath,Str_filePath)
{
	//alert(strURL);

	var SetVotesAtPrevious;var SetVotesAtContent;var getChioceRes3;
	var req = getXMLHTTP();
	if(req)
	{
		req.onreadystatechange = function()
		{
			if(req.readyState == 4)
			{ 
				if (req.status == 200)
				{	
					init() ;
					var AjaxStr = req.responseText;
					AjaxStr = AjaxStr.split('/');
					var getIndex = strURL.indexOf("choice_jk");
					var getChioceRes1 = strURL.substr(getIndex,strURL.length);
					var getChioceRes2 = getChioceRes1.indexOf("=");
					getChioceRes3 = getChioceRes1.substr(getChioceRes2+1,getChioceRes1.length);
					SetVotesAtPrevious = document.getElementById('rateIt'+Int_cnt);
					SetVotesAtContent = document.getElementById('jk_title'+Int_cnt);
					getTitle = document.getElementById('preTitle'+Int_cnt).value;
					var getT = SetVotesAtContent.innerHTML;
					
					var Str_vote1,Str_vote2, Str_vote3;
					if(AjaxStr[1] == 0) // 0=Not voted
					{
						try
						{
							if(getChioceRes3 == 1) //Liked 
							{ 
                                if(AjaxStr[2] > 0)
								{
	
									Str_vote1 = '<strong class="prev">&nbsp;'+StrPre+':&nbsp;<a>'+getTitle+'</a></strong> <img src="'+Str_basePath+''+Str_filePath+'/pictures/smile.gif" width="20" height="19" alt="smile"> <strong>' + AjaxStr[2] +'%</strong>&nbsp;'+StrFunny+'.';
									Str_vote2 = '<strong class="prev">&nbsp;'+StrThanks+'</strong> <img src="'+Str_basePath+''+Str_filePath+'/pictures/smile.gif" width="20" height="19" alt="smile"> <strong>' + AjaxStr[2] +'%</strong>&nbsp;'+StrFunny+'.';	
									getPreviousVote = Str_vote1;
									document.getElementById('previously').value = getPreviousVote;
									var x = document.getElementById("aa"+Int_cnt);
									if(getT.indexOf(StrRate) != -1)
									{
										x.style.display = 'none'; 
									}
									else
									{
										x.style.display = 'block'; 
									}
								}
								else
								{
									
									//Str_vote1='<div class="AccordionTitle-blue"><span>Rate these Cartoons and see if others agree!#1</span></div>'; 
									Str_vote1 = '<strong class="prev">&nbsp;'+StrPre+':&nbsp;<a>'+getTitle+'</a></strong> <img src="'+Str_basePath+''+Str_filePath+'/pictures/smile.gif" width="20" height="19" alt="smile"> <strong>100%</strong>&nbsp;'+StrFunny+'.';
								//Str_vote1 = '<strong class="prev">&nbsp;Thanks for voting!</strong>';
								Str_vote2 = '<strong class="prev">&nbsp;'+StrThanks+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong>';
								var x = document.getElementById("aa"+Int_cnt); 
								getPreviousVote = Str_vote1;
								document.getElementById('previously').value = Str_vote1;
									if(getT.indexOf('Rate these') != -1)
									{
										x.style.display = 'none'; 
									}
									else
									{
										x.style.display = 'block'; 
									}
								}
							}
							else
							{ 
							
								if(AjaxStr[2] > 0)
								{
									Str_vote1 = '<strong class="prev">&nbsp;'+StrPre+':&nbsp;<a>'+getTitle+'...</a></strong> <img src="'+Str_basePath+''+Str_filePath+'/pictures/sad-face.gif" width="20" height="19" alt="smile"> <strong>' + AjaxStr[2] +'%</strong>&nbsp;'+StrNF+'.';
									Str_vote2 = '<strong class="prev">&nbsp;'+StrThanks+'</strong> <img src="'+Str_basePath+''+Str_filePath+'/pictures/sad-face.gif" width="20" height="19" alt="smile"> <strong>' + AjaxStr[2] +'%</strong>&nbsp;'+StrNF+'.';
									getPreviousVote = Str_vote1;
									document.getElementById('previously').value = getPreviousVote;
									var x = document.getElementById("aa"+Int_cnt); 
									if(getT.indexOf('Rate these') != -1)
									{
										x.style.display = 'none'; 
									}
									else
									{
										x.style.display = 'block'; 
									}
								}
								else
								{
									//Str_vote1='<div class="AccordionTitle-blue"><span>Rate these Cartoons and see if others agree!#1</span></div>'; 
									Str_vote1 = '<strong class="prev">&nbsp;'+StrPre+':&nbsp;<a>'+getTitle+'</a></strong> <img src="'+Str_basePath+''+Str_filePath+'/pictures/sad-face.gif" width="20" height="19" alt="smile"> <strong>100%&nbsp;</strong>'+StrNF+'.';
								//Str_vote1 = '<strong class="prev">&nbsp;Thanks for voting!</strong>';
								Str_vote2 = '<strong class="prev">&nbsp;'+StrThanks+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong>';
								var x = document.getElementById("aa"+Int_cnt);
								getPreviousVote = Str_vote1;
								document.getElementById('previously').value = Str_vote1;
									if(getT.indexOf('Rate these') != -1)
									{
										x.style.display = 'none'; 
									}
									else
									{
										x.style.display = 'block'; 
									}
								}
								
							}							
						//	SetVotesAtContent.innerHTML = Str_vote1;
							SetVotesAtPrevious.innerHTML= Str_vote2;
						}
						catch(err)
						{
							alert("Error:"+err);
						
						}
					
					}
					
					else //1= Already voted
					{
						if(getChioceRes3 == 1)
						{
							if(AjaxStr[2] > 0)
							{
                           
							Str_vote1 = '<strong class="prev">&nbsp;'+StrPre+':&nbsp;<a>'+getTitle+'</a></strong> <img src="'+Str_basePath+''+Str_filePath+'/pictures/smile.gif" width="20" height="19" alt="smile"> <strong>' + AjaxStr[2] +'%</strong>&nbsp;'+StrFunny+'.';
							Str_vote2 = '<strong class="prev">&nbsp;'+StrSorry+'</strong>';
							getPreviousVote = Str_vote1;
							document.getElementById('previously').value = getPreviousVote;
							var x = document.getElementById("aa"+Int_cnt); 
							if(getT.indexOf('Rate these') != -1)
									{
										x.style.display = 'none'; 
									}
									else
									{
										x.style.display = 'block'; 
									}
							}
							else
							{
								Str_vote1 = '<strong class="prev">&nbsp;'+StrPre+':&nbsp;<a>'+getTitle+'</a></strong> <img src="'+Str_basePath+''+Str_filePath+'/pictures/smile.gif" width="20" height="19" alt="smile"> <strong>100%</strong>&nbsp;'+StrFunny+'.';
								Str_vote2 = '<strong class="prev">'+StrSorry+'</strong>';
								getPreviousVote = Str_vote1;
								document.getElementById('previously').value = getPreviousVote;
								var x = document.getElementById("aa"+Int_cnt);  x.style.display = 'block';
								if(getT.indexOf(StrRate) != -1)
									{
										x.style.display = 'none'; 
									}
									else
									{
										x.style.display = 'block'; 
									}
							}
						}
						else
						{
							if(AjaxStr[2] > 0)
							{
                           
							Str_vote1 = '<strong class="prev">&nbsp;'+StrPre+':&nbsp;<a>'+getTitle+'</a></strong> <img src="'+Str_basePath+''+Str_filePath+'/pictures/sad-face.gif" width="20" height="19" alt="smile"> <strong>' + AjaxStr[2] +'%&nbsp;</strong>'+StrNF+'.';
							Str_vote2 = '<strong class="prev">&nbsp;'+StrSorry+'</strong>';
							getPreviousVote = Str_vote1;
							document.getElementById('previously').value = getPreviousVote;
							var x = document.getElementById("aa"+Int_cnt);   x.style.display = 'block';
							if(getT.indexOf(StrRate) != -1)
									{
										x.style.display = 'none'; 
									}
									else
									{
										x.style.display = 'block'; 
									}
							}
							else
							{
								Str_vote1 = '<strong class="prev">&nbsp;'+StrPre+':&nbsp;<a>'+getTitle+'</a></strong> <img src="'+Str_basePath+''+Str_filePath+'/pictures/sad-face.gif" width="20" height="19" alt="smile"> <strong>100%&nbsp;</strong>'+StrNF+'.';
								Str_vote2 = '<strong class="prev">'+StrSorry+'</strong>';
								getPreviousVote = Str_vote1;
								document.getElementById('previously').value = getPreviousVote;
								var x = document.getElementById("aa"+Int_cnt); 
								if(getT.indexOf('Rate these') != -1)//Need to updated
								{
										x.style.display = 'none'; 
								}
								else
								{
										x.style.display = 'block'; 
								}
							}
						}	
						//SetVotesAtContent.innerHTML = Str_vote1;
						
						
						SetVotesAtPrevious.innerHTML= Str_vote2;	
					}
					
					var x = document.getElementById("aa"+Int_cnt);
					
			}
			else
			{ 
				alert("There was a problem while using XMLHTTP:\n");
			}
		}            
	}    
	
	req.open("GET", strURL, true); //open url using get method
	req.send(null);
	}
}






function changeImage(index)
{
		var getNid = 'undefined';
		if(previousNid == ''){previousNid = index;}
		else{ getNid = index;}	
		try
		{
		    var x = document.getElementById("aa"+index);
		    var source = x.src;
			var top_arrow_index = source.indexOf("top");
			var down_arrow_index = source.indexOf("bottom");
			if(top_arrow_index>=0)
            {
				//alert("top");
				arrowstr = source.substr(top_arrow_index,(source.length));
	            sourcestr = source.substr(0,top_arrow_index);
				deststr = sourcestr+'top-arrow-grey.gif';	
				x.setAttribute("src", deststr);
				//document.getElementById("jk_title"+index).innerHTML = getPreviousVote;
					document.getElementById("jk_title"+index).innerHTML = document.getElementById("previously").value;
				if(getPreviousVote.indexOf('previously') > 0)
				{
					//deststr = sourcestr+'top-arrow-grey.gif';	
					//x.setAttribute("src", deststr);
				}
			}
			if(down_arrow_index >=0)
            {
				//alert("bottom");
				arrowstr = source.substr(top_arrow_index,(source.length));
	            sourcestr = source.substr(0,top_arrow_index);
				deststr = sourcestr+'top-arrow-grey.gif';	
				
				x.setAttribute("src", deststr);
			}
            if(previousNid == getNid)
            {
				//alert("same");
			}
			
			var getState =	document.getElementById("previously").value;
			var SetVotesAtContent =  document.getElementById('jk_title'+ index);
			var getT = SetVotesAtContent.innerHTML;
			//alert(getState);
			if(getT.indexOf(StrRate) != -1)//Need to updated
			{
				x.style.display = 'none'; 
			}
			else
			{
				x.style.display = 'block'; 
			}
			var SplitState = getState.split('#');
			
			if(SplitState[1] == 1)
			{ 

				//x.style.display = 'none';
			}
			else
			{
				//x.style.display = 'block';
			}

		}
		catch(Err){	}				
}



function changeImage_onskip(strURL,Int_count,basepath,filepath)
{ 
   //GET http://localhost/RDA_tortoise/Ajax_jk_carousel.php?jk_tid=4&count=2&f=files&b=/RDA_tortoise/&tc=10 (985ms)
	var getIndex = strURL.indexOf("count");
    var getCountRes1 = strURL.substr(getIndex,strURL.length);
	var getCountRes2 = getCountRes1.indexOf("=");
	var getTotal = getIndex + getCountRes2;
	var getStrPart1 = strURL.substr(getTotal,strURL.length);
	var getCountRes3 =  getStrPart1.indexOf("&");
	var getStrPart2 = strURL.substr((getTotal+getCountRes3),strURL.length);
	var getStrPart1 = strURL.substr(0,getTotal+1);	
	var setStrpart1 = getStrPart1+(Int_count+1);
	var StrUrl =setStrpart1+getStrPart2;
	Ajax_Carousel(StrUrl,Int_count+1,basepath,filepath);

}

