
/*function play() {

  if (ytplayer) {

	ytplayer.playVideo();

  }

}*/


// Get element holding the video (embed or object)
//var player = document.getElementById("youtube");

//Create a simple function and check if player exists
/*function play() {
    if(player) {
        player.playVideo();
    }
}*/

    /*  var params = { allowScriptAccess: "always" };
      var atts = { id: "myytplayer" };
      swfobject.embedSWF("http://www.youtube.com/v/OQSNhk5ICTI&enablejsapi=1&playerapiid=ytplayer", "ytapiplayer", "425", "365", "8", null, null, params, atts);

      function onYouTubePlayerReady(playerId) {
        ytplayer = document.getElementById("myytplayer");
      }

      function play() {
        if (ytplayer) {
          ytplayer.playVideo();
        }
      }*/

var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };

function onYouTubePlayerReady() {
	ytplayer = document.getElementById("myytplayer");
}

function play() {
	if(ytplayer) {
		ytplayer.playVideo();
	}
}

function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("myytplayer");
	ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}

function onytplayerStateChange(newState) {
	if(newState == '0' || newState == '2') {
		$('#play-episode').html('Resume');
		
		$('.left').animate({
			left: '+=300'
		}, 1000, function()	{
			
		});
	}
}


$(document).ready(function() {
					
	$('.images').cycle('fade');
	
	/*
		Image Gallery
	*/
	
	$(".image-gallery .item").mouseover(function() {
		$(this).children().css({
			'background-color' : '#1ac7e0' ,
			'border-color' : '#1ac7e0' ,
			'cursor' : 'pointer'
		});
	}).mouseout(function(){
		$(this).children().css({
			'background-color' : '#222222' ,
			'border-color' : '#222222' ,
			'cursor' : 'default'
		});
	});
	
	$('.image-gallery .item').live('click', function() {
		var image = $(this).children('img').attr('src');
		image = image.split("thumb-");
		image = image[1];
		
		alert(image);
	})
	
	$("a[rel=images]").fancybox({
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	$('.contribution').hide();
	
	var current;
	var open = 0;
	
	$('.view-contribution').live('click', function() {
		var id = $(this).attr('id');
		
		if(open == 0) {
			$('#view-' + id).slideDown('slow');
			current = id;
			open = 1;
		} else {
			if(id == current) {
				$('#view-' + current).slideUp('slow');
				open = 0;
			} else {
				$('#view-' + current).slideUp('slow', function() {
					$('#view-' + id).slideDown('slow');
					current = id;
				});
			}
		}
	});
	
	$(".name").focus(function () {
		var value = $(this).val();
		$(this).attr('class', 'input name');
		if(value == "" || value == "Please enter your name.") {
			$(this).attr('value', '');
		}
	});
	
	$(".name").focusout(function() {
		var value = $(this).val();
		$(this).attr('class', 'input name');
		if(value == "") {
			$(this).attr('value', '');
		}
	});
	
	$(".email").focus(function () {
		var value = $(this).val();
		$(this).attr('class', 'input email');
		if(value == "Please enter your email." || value == "Please enter a valid email.") {
			$(this).attr('value', '');
		}
	});
	
	$(".email").focusout(function() {
		$(this).attr('class', 'input email');
	});
	
	$(".message").focus(function () {
		var value = $('textarea.message').val();
		$(this).attr('class', 'textarea message');
		if(value == '' || value == 'Please enter a message.') {
			$('textarea.message').attr('value', '');
		}
	});
	
	$(".message").focusout(function() {
		var value = $('textarea.message').val();
		$(this).attr('class', 'textarea message');
	});
	
	$('.submit').live('click', function() {
		var error = 0;
		
		var error = 0;
		var emailReg = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
		
		var contact_name = $(".name").val();
		var contact_email = $(".email").val();
		var contact_message = $("textarea.message").val();
		
		if(contact_name == "" || contact_name == "Please enter your name.") {
			$(".name").attr('class', 'input name error');
			$(".name").attr('value', 'Please enter your name.');
			error++;
		} else {
			$(".name").attr('class', 'input name');
		}
		
		if(contact_email == "" || contact_email == "Please enter a valid email." || contact_email == "Please enter your email.") {
			$(".email").attr('class', 'input email error');
			$(".email").attr('value', 'Please enter your email.');
			error++;
		} else if(!emailReg.test(contact_email)) {
			$(".email").attr('class', 'input email error');
			$(".email").attr('value', 'Please enter a valid email.');
			error++;
		} else {
			$(".email").attr('class', 'input email');
		}
		
		if(contact_message == "" || contact_message == "Please enter a message.") {
			error++;
			$(".message").attr('class', 'textarea message error');
			$(".message").attr('value', 'Please enter a message.');
		} else {
			$(".message").attr('class', 'textarea message');
		}
		
		if(error == 0) {
			$.post("http://www.explore22.com/contact", { name: contact_name , email: contact_email , message: contact_message , type: "contact" } ,
			function(data) {
				if(data == "1") {
					$('#contact-form').fadeOut(300, function () {
						$('#contact-success').fadeIn('slow');
					});
				} else {
					$('.submit').attr('class', 'submit error');
					$('.submit').attr('value', 'Error - Your message could not be sent.');
				}
			});
		}
		
		return false;
	});
	
	$('#donate').live('click', function() {
		
	});
});
