// set the starting image.
var i = 0;		

// The array of div names which will hold the images.
var image_slide = new Array('image-1', 'image-2', 'image-3', 'image-4');

// The array of div names (tabs).
var image_tab = new Array('tab-1', 'tab-2', 'tab-3', 'tab-4');

// Array of titles
var title = new Array('title-1', 'title-2', 'title-3', 'title-4');

// Array of authors
var author = new Array('author-1', 'author-2', 'author-3', 'author-4');

// The number of images in the array.
var NumOfImages = image_slide.length;

// The time to wait before moving to the next image. Set to 3 seconds by default.
var wait = 13777;

//default 13777

// The Fade Function & Tab Change
function SwapImage(x,y) {
	var z, b;
	var z = x;
	var b = y;
	$(image_slide[x]).appear({ duration: 1.5 });
	$(image_slide[y]).fade({duration: 1.5});
	document.getElementById(image_tab[z]).style.background="white";
	document.getElementById(image_tab[z]).style.color="white";
	document.getElementById(title[z]).style.color="#666666";
	document.getElementById(author[z]).style.color="#414141";
	document.getElementById(image_tab[b]).style.background="#4b4b4b";
	document.getElementById(image_tab[b]).style.color="#454545";
	document.getElementById(title[b]).style.color="#66ccff";
	document.getElementById(author[b]).style.color="#CCCCCC";
	
}

// the onload event handler that starts the fading.
function StartSlideShow() {
	play = setInterval('Play()',wait);
	$('PlayButton').hide();
	$('PauseButton').appear({ duration: 0});
								
}

function Play() {
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;
	
	if (imageShow == NumOfImages) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

function Stop () {
	clearInterval(play);				
	$('PlayButton').appear({ duration: 0});
	$('PauseButton').hide();
}

function GoNext() {
	clearInterval(play);
	StartSlideShow();
	// $('PlayButton').appear({ duration: 0});
	// $('PauseButton').hide();
	
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;
	
	if (imageShow == NumOfImages) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

function GoPrevious() {
	clearInterval(play);
	StartSlideShow();
	// $('PlayButton').appear({ duration: 0});
	// $('PauseButton').hide();

	var imageShow, imageHide;
				
	imageShow = i-1;
	imageHide = i;
	
	if (i == 0) {
		SwapImage(NumOfImages-1,imageHide);	
		i = NumOfImages-1;		
		
		//alert(NumOfImages-1 + ' and ' + imageHide + ' i=' + i)
					
	} else {
		SwapImage(imageShow,imageHide);			
		i--;
		
		//alert(imageShow + ' and ' + imageHide)
	}
}

function Get_4() {
	clearInterval(play);
	StartSlideShow();
	
	if( i != 3 ) {
		var imageShow, imageHide;
		imageHide = i;
		imageShow = 3;
		SwapImage(imageShow, imageHide);
	}
	i = 3;
	
}

function Get_3() {
	clearInterval(play);
	StartSlideShow();
	
	if( i != 2 ) {
		var imageShow, imageHide;
		imageHide = i;
		imageShow = 2;
		SwapImage(imageShow, imageHide);
	}
	
	i = 2;
}

function Get_2() {
	clearInterval(play);
	StartSlideShow();
	
	if( i != 1 ) {
		var imageShow, imageHide;
		imageHide = i;
		imageShow = 1;
		SwapImage(imageShow, imageHide);
	}
	
	i = 1;
}

function Get_1() {
	clearInterval(play);
	StartSlideShow();
	
	if( i != 0 ) {
		var imageShow, imageHide;
		imageHide = i;
		imageShow = 0;
		SwapImage(imageShow, imageHide);
	}
	
	i = 0;
}

var allHTMLTags = new Array();

function getElementByClass(theClass) {

	var allHTMLTags=document.getElementsByTagName("*");
	
	
	for (i=0; i<allHTMLTags.length; i++) {

		if (allHTMLTags[i].className==theClass && allHTMLTags[i].checked==false) {
			allHTMLTags[i].checked=true;
		}
		
		else allHTMLTags[i].checked=false;
	}
	
	if (document.getElementById('checkthem').checked == false) {
		document.getElementById('checkthem').checked=true;
	}
	else document.getElementById('checkthem').checked=false;
	
}

//<![CDATA[
function ShowHideMenu(){
  if (document.getElementById('dropdown').style.display=='')
    document.getElementById('dropdown').style.display='none';    
  else document.getElementById('dropdown').style.display=''; 
}
var operation = -1;
function handleHttpResponse()
{

	if (http.readyState == 4)
	{ 	
		var rez = http.responseText;
		var niz = rez.split('!!!');
		
		if (operation == 'global_news')
        {		  
	        document.getElementById('globalnews_body').innerHTML = niz[0];
	        document.getElementById('global_news_menu_div').innerHTML = niz[1];
	        ///alert(niz[1]);
	       // alert(niz[1]);
          //document.getElementById('globalnews_menu_tr').innerHTML = "fasdfasdf"; 
        }
        else if (operation == 'main_menu')
        {
	       document.getElementById('main_menu_tr').innerHTML = niz[0];
	       document.getElementById('sub_menu_tr').innerHTML = niz[1];         
        }        	
	}
 	else
 	{
 	}
}

function sendRequest(adresa,oper)
{	
  url = location.protocol + '//' + location.host + "/" + adresa;
    operation = oper;
	http.open("GET", url, true);	  
  http.onreadystatechange = handleHttpResponse;  
  http.send(null);   
}

function getHTTPObject()
{
 var C=null;
 try
 {
  C=new ActiveXObject("Msxml2.XMLHTTP")
 }
 catch(e)
 {
  try
  {
   C=new ActiveXObject("Microsoft.XMLHTTP")
  }
  catch(sc)
  {
   C=null
  }
 }
 if(!C&&typeof XMLHttpRequest!="undefined")
 {
  C=new XMLHttpRequest()
 }
 return C
}
var http = getHTTPObject(); //HTTP Object 
//]]>

function show_detail(val)
{  
	var url = location.protocol + '//' + location.host + "/show_detail.php?val="+val;
	if (window.XMLHttpRequest) // code for Mozilla, etc.
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) // code for IE
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp != null)
	{
		try
		{
			xmlhttp.onreadystatechange=stateChanged8;
			xmlhttp.open("GET", url, true);
			xmlhttp.send(null);			
		}
		catch(ex)
		{
			alert("Your browser returned AJAX error " + ex);
		}
	}
	else
	{
		alert("Your browser does not support XMLHTTP.");
	}
	return false;
}

function stateChanged8()
{
	if(xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
	{
		if(xmlhttp.status==200)
		{	
		document.getElementById("display_detail").innerHTML=xmlhttp.responseText;				
		xmlhttp=null;			
		}
	}
}

function more_news(val)
{  
	var url = location.protocol + '//' + location.host + "/show_more_news.php?val="+val;
	if (window.XMLHttpRequest) // code for Mozilla, etc.
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) // code for IE
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp != null)
	{
		try
		{
			xmlhttp.onreadystatechange=stateChanged9;
			xmlhttp.open("GET", url, true);
			xmlhttp.send(null);			
		}
		catch(ex)
		{
			alert("Your browser returned AJAX error " + ex);
		}
	}
	else
	{
		alert("Your browser does not support XMLHTTP.");
	}
	return false;
}
function stateChanged9()
{
	if(xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
	{
		if(xmlhttp.status==200)
		{			
		document.getElementById("show_more_news").innerHTML=xmlhttp.responseText;				
		xmlhttp=null;			
		}
	}
}

var breaking_news = new Array('news-1', 'news-2', 'news-3', 'news-4');

var nold = 0;
var nselected = 0;

function swapColor (nselected) {

	document.getElementById(breaking_news[nold]).style.color="#333";
	document.getElementById(breaking_news[nselected]).style.color="#666";

	nold = nselected;

}

function more_news(val)
{  
	var url = location.protocol + '//' + location.host + "/show_more_news.php?val="+val;
	if (window.XMLHttpRequest) // code for Mozilla, etc.
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) // code for IE
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp != null)
	{
		try
		{
			xmlhttp.onreadystatechange=stateChanged9;
			xmlhttp.open("GET", url, true);
			xmlhttp.send(null);			
		}
		catch(ex)
		{
			alert("Your browser returned AJAX error " + ex);
		}
	}
	else
	{
		alert("Your browser does not support XMLHTTP.");
	}
	return false;
}
function stateChanged9()
{
	if(xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
	{
		if(xmlhttp.status==200)
		{			
		document.getElementById("show_more_news").innerHTML=xmlhttp.responseText;				
		xmlhttp=null;			
		}
	}
}
function calcCharLeft() {
    clipped = false
    lenUSig = 0
    maxLength =140
        if (document.message_post.description.value.length > maxLength) { 
            document.message_post.description.value = document.message_post.description.value.substring(0,maxLength)
        charleft = 0
        clipped = true
        } else {
        charleft = maxLength - document.message_post.description.value.length
    }
        document.message_post.counter.value = charleft
        return clipped
}

function textKey() {
    supportsKeys = true
    calcCharLeft()
}
function set_put_id_value(val)
{
    document.getElementById('direct_post').value = '';
    document.getElementById('putid').value += val + " ";
    document.getElementById('putid').focus();
    
}
function retweet_message(val)
{
    document.getElementById('direct_post').value = '';
    document.getElementById('putid').value = val;
    document.getElementById('putid').focus();
}
function tweet_direct_message(val)
{ 
    document.getElementById('direct_post').value = val;
    document.getElementById('putid').value = "D";
    document.getElementById('putid').focus();
}


var pop = new Array('pop-1', 'pop-2', 'pop-3');

var xold = 1;
var xnew = 0;

function swapPopular (xnew) {

	document.getElementById(pop[xold]).style.color="#333";
	document.getElementById(pop[xnew]).style.color="#666";

	xold = xnew;

}

function get_most_popular(pop,type)
{  
	var url = location.protocol + '//' + location.host + "/get_most_popular.php?pop="+pop+"&type="+type;
	if (window.XMLHttpRequest) // code for Mozilla, etc.
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) // code for IE
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp != null)
	{
		try
		{
			xmlhttp.onreadystatechange=stateChanged11;
			xmlhttp.open("GET", url, true);
			xmlhttp.send(null);			
		}
		catch(ex)
		{
			alert("Your browser returned AJAX error " + ex);
		}
	}
	else
	{
		alert("Your browser does not support XMLHTTP.");
	}
	return false;
}
function stateChanged11()
{
	if(xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
	{
		if(xmlhttp.status==200)
		{			
		document.getElementById("get_most_popular_ch").innerHTML=xmlhttp.responseText;				
		xmlhttp=null;			
		}
	}
}
