// Global variables
var leftAd = 0;
var adsHidden = false;
var firstRun = true;

google_ad_client = "pub-2496829165139503";
/* 250x250, created 3/12/10 */
google_ad_slot = "0743858659";
google_ad_width = 250;
google_ad_height = 250;

// Things to do on load
$(document).ready(function()
{
	setTimeout("resumeAds()", 12000);
	setTimeout("checkWidthForAds()", 100);
});

function checkWidthForAds()
{
	if(getWindowDimensions("width") > 1200)
	{
		adsHidden = false;
		
		$('#leftPanel').css('display', 'none');
		$('#rightPanel').css('display', 'none');
		
		$('#adLeftText').css('display', 'inline');
		$('#adLeftImage').css('display', 'inline');
		$('#adRightText').css('display', 'inline');
		$('#adRightImage').css('display', 'inline');
		$('#vineRight').css('display', 'inline');
		$('#vineLeft').css('display', 'inline');
		$('#shadowRight').css('display', 'inline');
		$('#shadowLeft').css('display', 'inline');
		
		$('#adLeftText').animate({opacity: '1'}, 'slow');
		$('#adLeftImage').animate({opacity: '0.2'}, 'slow');
		$('#adRightText').animate({opacity: '1'}, 'slow');
		$('#adRightImage').animate({opacity: '0.2'}, 'slow');
		$('#vineRight').animate({opacity: '0.2'}, 'slow');
		$('#vineLeft').animate({opacity: '0.2'}, 'slow');
		$('#shadowRight').animate({opacity: '0.2'}, 'slow');
		$('#shadowLeft').animate({opacity: '0.2'}, 'slow');
	}
	else
	{
		adsHidden = true;
		
		$('#adLeftText').animate({opacity: '0'}, 'slow');
		$('#adLeftImage').animate({opacity: '0'}, 'slow');
		$('#adRightText').animate({opacity: '0'}, 'slow');
		$('#adRightImage').animate({opacity: '0'}, 'slow');
		$('#vineRight').animate({opacity: '0'}, 'slow');
		$('#vineLeft').animate({opacity: '0'}, 'slow');
		$('#shadowRight').animate({opacity: '0'}, 'slow');
		$('#shadowLeft').animate({opacity: '0'}, 'slow');
		
		$('#adLeftText').css('display', 'none');
		$('#adLeftImage').css('display', 'none');
		$('#adRightText').css('display', 'none');
		$('#adRightImage').css('display', 'none');
		$('#vineRight').css('display', 'none');
		$('#vineLeft').css('display', 'none');
		$('#shadowRight').css('display', 'none');
		$('#shadowLeft').css('display', 'none');
		
		$('#leftPanel').css('display', 'inline');
		$('#rightPanel').css('display', 'inline');
	}

	firstRun = false;
	setTimeout("checkWidthForAds()", 1000);
}

// change ads and set new change schedule for 10s (12000 accounts for fade out and fade in of new ads)
function resumeAds()
{
	if(!adsHidden)
		switchLeftAd();
		
	setTimeout("resumeAds()", 10000);
}

function switchLeftAd()
{
	$('#adLeftImage').animate({opacity: 0.0}, 1000);
	$('#adLeftText').animate({opacity: 0.0}, 1000);
	
	if(leftAd == 0)
	{
		leftAd = 1;
		setTimeout("$('#googleAd').css('display','none');$('#otherAd').css('display','block')", 1100);
		//setTimeout("$('#adLeftText').html(\"Got a message to get<br/>across to the musical<br/>Canberrans?<br/><br/>Shout it out here!\")", 1100);
	}
	else
	{
		leftAd = 0;
		setTimeout("$('#googleAd').css('display','block');$('#otherAd').css('display','none')", 1100);
		//setTimeout("$('#adLeftText').html('Contact us if you<br/>would like to see<br/>your business advertised here!')", 1100);
	}
	
	setTimeout("if(!adsHidden)reshowLeftAd()", 1200); // fade ads in 200ms after change of text
}

function reshowLeftAd()
{
	// fade in for 2s
	if(!adsHidden)
	{
		$('#adLeftImage').animate({opacity: 0.2}, 1000);
		$('#adLeftText').animate({opacity: 1.0}, 1000)
	}
}

/*
function switchRightAd(arg)
{	
	if(!adsHidden)
	{
		$('#adRightText').animate({opacity: 0.0}, 200);
		setTimeout("$('#adRightText').css('bottom','215px')", 225);
		
		if(arg == 'home')
		{
			setTimeout("$('#adRightText').html('<div style=\"text-align:center;\"><div class=\"advertisingText\" style=\"text-align:center;font-size:20px;\">Home</div><br/><br/>News&nbsp;&nbsp;&nbsp;Events&nbsp;&nbsp;&nbsp;Updates<br/><br/>Get the news...<br/>Locate a gig...<br/>Browse the calendar...</div>')",250);
		}
		else if(arg == 'media')
		{
			setTimeout("$('#adRightText').html('<div style=\"text-align:center;\"><div class=\"advertisingText\" style=\"text-align:center;font-size:20px;\">Media</div><br/><br/>Music&nbsp;&nbsp;&nbsp;Lyrics&nbsp;&nbsp;&nbsp;Videos&nbsp;&nbsp;&nbsp;Photos<br/><br/>Browse the list...<br/>Download and learn...<br/>Make a request...</div>')",250);
		}
		else if(arg == 'classifieds')
		{
			setTimeout("$('#adRightText').html('<div style=\"text-align:center;\"><div class=\"advertisingText\" style=\"text-align:center;font-size:20px;\">Classifieds</div><br/><br/>Buying&nbsp;&nbsp;&nbsp;Selling&nbsp;&nbsp;&nbsp;Swapping&nbsp;&nbsp;&nbsp;Enquiring<br/><br/>Browse the listings...<br/>Request information...<br/>Sell an item...</div>')",250);
		}
		else if(arg == 'forum')
		{
			setTimeout("$('#adRightText').html('<div style=\"text-align:center;\"><div class=\"advertisingText\" style=\"text-align:center;font-size:20px;\">Forum</div><br/><br/>Chat with other musicians...<br/>Call for band members...<br/>Discuss shows...</div>')",250);
		}
		else if(arg == 'links')
		{
			setTimeout("$('#adRightText').html('<div style=\"text-align:center;\"><div class=\"advertisingText\" style=\"text-align:center;font-size:20px;\">Links</div><br/><br/>Visit related websites...<br/>Add your link...<br/>Bookmark your favourites...</div>')",250);
		}
		
		//setTimeout("if(!adsHidden)$('#adRightText').animate({opacity: 1.0}, 200)", 300);
	}
}
*/

/*
function menuOff()
{
	if(!adsHidden)
	{
		$('#adRightText').animate({opacity: 0.0}, 200);
		setTimeout("loggedIn()",250);
		
		//setTimeout("if(!adsHidden)$('#adRightText').animate({opacity: 1.0}, 200)", 300); // fade ads in 200ms after change of text
	}
}*/

var loggedInXMLHTTPObject = null;
function loggedIn()
{
	loggedInXMLHTTPObject = getXMLHTTPObject();
	if(loggedInXMLHTTPObject != null)
	{
		loggedInXMLHTTPObject.onreadystatechange = function()
		{
			if(loggedInXMLHTTPObject != null && loggedInXMLHTTPObject.readyState == 4)
			{
				if(loggedInXMLHTTPObject.responseText == "true")
				{
					$('#adRightText').html('<div style=\"text-align:justify;color:#E38102\">If you have any problems with the website or questions on how to do something please send us a message through the contact page. We will respond as soon as we can and sort out the problems much quicker with your help.</div>');
				}
				else // just show registration message
				{
					var sPath = window.location.pathname;
					if(sPath.indexOf("index.php") == -1)
					{
						$('#adRightText').html('<div class=\"advertisingText\" style=\"text-align:center;font-size:20px;\"><a href=\"index.php?showrego=yes\" id=\"regoLink\" style=\"cursor:pointer;text-decoration:none;\">Register Now<br/><br/>It&#39;s Free!</a></div>');
					}
					else
					{
						$('#adRightText').html('<div class=\"advertisingText\" style=\"text-align:center;font-size:20px;\"><a id=\"regoLink\" onclick=\"showRegistration()\" style=\"text-decoration:none;cursor:pointer;\">Register Now<br/><br/>It&#39;s Free!</a></div>');
					}
					
					$('#adRightText').css('bottom','205px');
				}
				
				loggedInXMLHTTPObject = null;
			}
		};
		
		loggedInXMLHTTPObject.open("GET", "checkLoggedIn.php", true);
		loggedInXMLHTTPObject.send(null);
	}
	else
		alert('Your browser does not support AJAX!');
}
		
function getWindowDimensions(arg)
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' )
  {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
  }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
  {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
  {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }

  if(arg == "width")
	return myWidth;
  else if(arg == "height")
	return myHeight;
}