 // The jquery code for every page
 
$(document).ready(function() {		
	  	  	  
	// Since we have javascript enabled, then all classes with has javascript gets removed
	$('.has_javascript').hide();

	//Load the slideshow
	setInterval('rotate()',8000);
	
	//Do a quick check if admin is online
	checkifadminonline();
	
	// Check if Admin is online/offline - Look for admin_online file
	setInterval('checkifadminonline()',8000);
	
	// ONLY DO FADES IN MOZILLA
	// microsoft has hard time with transparent PNG files
	if (!($.browser.msie))  {
	
	    // A - FADE IN           
  		var $middle = $('#middle_wrapper');
  		var $bottom = $('#bottom_wrapper');
  		var $left2 = $('#top_body_left2');
		// The unload and .hide solve the flicker problem some browsers have.
   		$(window).bind("unload", function() {});
		$middle.css("display","none");
  		$middle.hide();
  		//$middle.cycle({
		//	cleartype:1 });
		$bottom.css("display","none");
  		$bottom.hide();
		$left2.css("display","none");
  		$left2.hide();
	
		// WAIT TILL THE DOM LOADS (images) BEFORE YOU fade 
		$(window).load(function(){
       		$middle.fadeTo(500,1);
			$bottom.fadeTo(500,1);
    	  	$left2.fadeTo(500,1);
  		})

		// B - On A fade out
		//  But if href is #, its not a redirect. So make a class "ignorefade" to ignore the fade
		if (!($("a").hasclass('ignorefade'))) {
	  		$("a").click(function(event){
    	  		event.preventDefault();
       			linkLocation = this.href;
				$middle.fadeTo(500,0);
        		$bottom.fadeTo(500,0,redirectPage);
      			$left2.fadeTo(500,0,redirectPage);
   			});
		}
	}
                 
    function redirectPage() {
     	window.location = linkLocation;
  	}
	
});

function rotate() {
	
	//this is done by adding and removing classes.
		
	//Get the first image
	var current = ($('div#quotes  .showquotes')?  $('div#quotes  .showquotes') : $('div#quotes  :first'));
	var current1 = ($('div#authors  .showauthors')?  $('div#authors  .showauthors') : $('div#authors  :first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('showquotes')) ? $('div#quotes  :first') :current.next()) : $('div#quotes  :first'));	
	var next1 = ((current1.next().length) ? ((current1.next().hasClass('showauthors')) ? $('div#authors  :first') :current1.next()) : $('div#authors  :first'));	
	
	//Hide the current image
	current.removeClass('showquotes').fadeOut(1000);
	current1.removeClass('showauthors').fadeOut(1000);
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.addClass('showquotes').fadeIn(1000);
	next1.addClass('showauthors').fadeIn(1000);

	}

function checkifadminonline() {

	// See if the file exists
	var adminonlinefile = "/simple_chat/logs/admin_online.html";

	$.ajax({
		url:adminonlinefile,
    	type:'GET',
		timeout: 1000,
    	error:
        	function(){
				// Remember the function returns nothing - So that;s why its blank
          	  	//The admin is offline
				if (!($.browser.msie))  { // because IE sucks
				  	$('div#container_rightside_chat_online').fadeOut(2000);
					$('div#container_rightside_chat_offline').fadeIn(1000);}
				else {
					$('div#container_rightside_chat_online').hide();
					$('div#container_rightside_chat_offline').show();
				}
       		 },
    	success:
        	function(html){
				// The funcion retuns the HTML in the file.  Pretty cool.
				// The admin is online
				if (!($.browser.msie))  { // because IE sucks
					$('div#container_rightside_chat_offline').fadeOut(2000);
					$('div#container_rightside_chat_online').fadeIn(1000);}
				else {
					$('div#container_rightside_chat_offline').hide();
					$('div#container_rightside_chat_online').show();
				}
        	}
		});
	}

				 

