(function($) { // Making $ accessible even in noConflict
  $(document).ready(function(){
		var toPlay = '';
		
		$(".fancybox").fancybox({
			autoSize: false, 
			padding: '0', 
			width: 560, 
			height: 344,
			type:'iframe',
			scrolling: false
		});
    
    // Adding placeholders for form fields
    if($.fn.placeholder)
    {
      $(".placeholder, [placeholder]").placeholder();
    }
    
    // Setting up contact form
    if($.fn.TFContactForm)
    {
      $('#contact-form').TFContactForm();
    }
  
		if ($.fn.cycle) {
			$('.cycle').cycle();	
		}
		
		if (window.location.pathname == '/testimonials.html') {
			$('.cycle a').click(function () {
				toPlay = $(this).attr('href').replace('#', '');
				var youtubeBox = $.get('/youtube-loader.html', {yt_id: toPlay}, function (data) {
					$.fancybox.open(
						$(data),
						{
							autoSize: false, 
							padding: '0', 
							width: 560, 
							height: 344, 
							scrolling: false
						}
					);
				});
				return false;
			});
		}
		
		else {
			$('.cycle a').click(function () {
				$(this).attr('href', '/testimonials.html');
				return true;
			});
		}
  
    // Adding basic validation to contact form
    if($.fn.slideshow)
    {
      $('#billboard').slideshow({
        timeout: 7000,
        fadetime: 1000,
        type: 'sequence'
      });
    }
  });
	
})(jQuery);



var player;
function onYouTubePlayerReady(playerId) {
	player = document.getElementById("ytPlayer");	
	player.loadPlaylist('5505CF3DC7B9489E');
	player.setLoop(true);
}

$(function () {
	var params = { allowScriptAccess: "always", wmode: 'transparent' };
	var atts = {id: "ytPlayer"};
	swfobject.embedSWF("http://www.youtube.com/apiplayer?" +
				 "version=3&enablejsapi=1&playerapiid=player1", 
				 "videoDiv", "242", "259", "9", null, null, params, atts);
	if (window.location.pathname == '/testimonials.html') {
		$('.youtube .title span').html('View this testimonial');
		$('.youtube-link').click(function () {
			player.pauseVideo();
			var videos = player.getPlaylist(),
					vIndex = player.getPlaylistIndex(),
					video  = videos[vIndex];
			$.get('/youtube-loader.html', {'yt_id': video}, function (data) {
				$.fancybox.open(
					$(data), 
					{
						autoSize: false, 
						padding: '0', 
						width: 560, 
						height: 344, 
						scrolling: false,
						afterClose: function () {
							player.playVideo();
						}
					});
			});
			return false;
		});
	}
});
