$(document).ready(function(){
	$(".rollover-jpg").hover(
		function(){
			if($(this).attr("src").indexOf("_over") == -1) {
				var newSrc = $(this).attr("src").replace(".jpg","_over.jpg#hover");
				$(this).attr("src",newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("_over.jpg#hover") != -1) {
				var oldSrc = $(this).attr("src").replace("_over.jpg#hover",".jpg");
				$(this).attr("src",oldSrc);
			}
		}
	);
});

$(document).ready(function(){
	$(".rollover-gif").hover(
		function(){
			if($(this).attr("src").indexOf("_over") == -1) {
				var newSrc = $(this).attr("src").replace(".gif","_over.gif#hover");
				$(this).attr("src",newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("_over.gif#hover") != -1) {
				var oldSrc = $(this).attr("src").replace("_over.gif#hover",".gif");
				$(this).attr("src",oldSrc);
			}
		}
	);
});


$(document).ready(function(){
	$(".rollover").hover(
		function(){
			if($(this).attr("src").indexOf("_over") == -1) {
				var newSrc = $(this).attr("src").replace(".png","_over.png#hover");
				$(this).attr("src",newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("_over.png#hover") != -1) {
				var oldSrc = $(this).attr("src").replace("_over.png#hover",".png");
				$(this).attr("src",oldSrc);
			}
		}
	); 

});
 
function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   } else {
	   return true;
   }
}



$(document).ready(function(){

	$("ul.topnav li.parents:not(:last-child)").append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.topnav li.drop").mouseover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
 
		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

});

function getStatues2(username, maxItems)	{
	$.ajax({
	   type: "GET",
	   url: "/getStatues.php",
	   data: "",
	   error: function(){
	   },
	   success: function(xml){
			$("#twitter").html('');
			$('item',xml).each(function(i){
				if (i < maxItems) {
					var title = $(this).find("title").text();
					title = title.substring(0, 200)+'...';
					title = title.replace(username+': ','');
					var pubDate = $(this).find("pubDate").text();
					var url = $(this).find("link").text();
					$("#twitter").append("<li><a href=\""+url+"\" target=_blank>"+title+"</a><span>"+pubDate+"</span></li>");
					i++;
				}
			});
	   }
	});
}

function getStatues(username, maxItems)	{
	$.get("/getStatues.php",  function(xml){
		var i = 0; 
		//var delay = 2500;
		$("#twitter").html('');
		$('item',xml).each(function(i){
			if (i < maxItems) {
				var title = $(this).find("title").text();
				title = title.substring(0, 200)+'...';
				title = title.replace(username+': ','');
				var pubDate = $(this).find("pubDate").text();
				var url = $(this).find("link").text();
				$("#twitter").append("<li><a href=\""+url+"\" target=_blank>"+title+"</a><span>"+pubDate+"</span></li>");
				i++;
			}
		});
	});	 
}



function sendContact() {
	var name = $("#your_name").val();
	var contact = $("#your_contact").val();
	
		
	if (name=='' || name == 'Your name') 		{ alert('Please enter you name'); return false; }
	if (contact=='' || contact == 'Contact number') 		{ alert('Please enter your number'); return false; }
	
	
	input_box = confirm("Is all information correct?");	
	if (input_box == true)	{
		$.ajax({
		   type: "POST",
		   url: "/send_contact.php",
		   data: "name="+name+"&contact="+contact,
				 
		   // on success
		   error: function(){
				alert('ooops! - nasty error. Please try again.')
		   },
		   success: function(data){
			    if (data == 'OK') {
					$("#your_name").val('');
					$("#your_contact").val('');
					
					$("#register_form").hide();
					
					$(".reg-result").fadeIn();
					
				} else {
			   		alert('ooops! - nasty error. Please try again.');
		   		}
		   } 
		});
		return true;
	}
	else {	
		return false; 	
	}
} 



// close other audio players
// called by audio player when click on play button 
function ap_stopAll(player_id)
{
	$('.audio_flash').each(function(){
		if($(this).attr('id') != player_id)
		{
			$(this).find('object')[0].SetVariable("closePlayer", 1);
		}
		else 
		{
			$(this).find('object')[0].SetVariable("closePlayer", 0);
		}
	});
}

$(document).ready(function() {

	$('.audio').each(function() {
		audio_file = $(this).attr('href'); 
		audio_title = $(this).text();
		audio_id = $(this).attr('id');
		
		div = $('<div class="audio_flash" id="' + audio_id + '"></div>');		
		$(this).after(div);
		$(this).after(audio_title);
		$(this).remove();
		div.flash(
			{
				swf: '/app/js/jquery_audio_player/flash/audioplayer.swf',
				flashvars:
				{
					soundFile: audio_file,
					playerID: "'" + audio_id + "'",
					quality: 'high',
					lefticon: '0xFFFFFF',
					righticon: '0xFFFFFF',
					leftbg: '0x078cc7',
					rightbg: '0xed8a00',
					rightbghover: '0x888888',
					wmode: 'transparent'
				},
				height: 50
			}
		);
	});

});

