function fbs_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}
function theRotator() {
	$j('#sidebar.video ul li').css({opacity: 0.0});
	$j('#sidebar.video ul li:first').css({opacity: 1.0});
	setInterval('rotate()',6000);
}
function rotate() {	
	var current = ($j('#sidebar.video ul li.show')?  $j('#sidebar.video ul li.show') : $j('#sidebar.video ul li:first'));
    if ( current.length == 0 ) current = $j('#sidebar.video ul li:first');
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $j('#sidebar.video ul li:first') :current.next()) : $j('#sidebar.video ul li:first'));
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};

var $j = jQuery.noConflict();
$j(document).ready(function() {
	jQuery(".trainingform").validationEngine();
	$j("a:has(.size-thumbnail)").fancybox();
	$j("a:has(.size-medium)").fancybox();
	$j("a:has(.size-large)").fancybox();
	//$j("a:has(.size-full)").fancybox();
	$j('a[rel^="fancybox"]').fancybox();
	$j(".video_gallery a").click(function() {
	$j.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		: 680,
			'height'		: 495,
			'href'	 : this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?autoplay=1&clip_id=$1'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});
		return false;
	});	
	/* Inline labelid */
	$j('input[title]').each(function() {
		if($j(this).val() === '') {
			$j(this).val($j(this).attr('title'));	
		}
		$j(this).focus(function() {
			if($j(this).val() == $j(this).attr('title')) {
				$j(this).val('').addClass('focused');	
			}
		});
		$j(this).blur(function() {
			if($j(this).val() === '') {
				$j(this).val($j(this).attr('title')).removeClass('focused');	
			}
		});
	});
	// Make Destemonial div clickable.
	$j(".bq").click(function(){
		 window.location=$j(this).find("a").attr("href");
		 return false;
	})
	$j('input:radio, input:checkbox').checkbox({
	  cls:'jquery-checkbox',
	  empty: globalurl+'/images/empty.png'
	});
	$j('.closebutton').click(function(){
		$j('.closebutton').hide();
		$j('#facebookshare').hide();
		if(ie == true){
			$j('.block.fb').show();
			$j('.trainingform').width('310');
			$j('.trainingform fieldset.right').hide();
			$j('.trainingform a.fsubmit').fadeIn();
			}
		else{
		$j('.hasform').animate({
			  width: '310px'
			}, 500, function() {
				$j('.trainingform fieldset.right').hide();
				$j('.trainingform a.fsubmit').fadeIn();
			});
		}
		return false;
	});
	$j('.trainingform a.fsubmit').click(function(){
		$j('.trainingform').validationEngine('validate');
		if( $j('.trainingform').validationEngine('validate') ){
		//fbs_click();
		ageval = $j('input[name$="0[age]"]').val();
		sexval = $j('input[name$="0[sex]"]:checked').val();
		oftsportval = $j('input[name$="0[oftsport]"]:checked').val();
		lang = $j('input[name$="0[lang]"]').val();
		if(lang == "es"){ submiturl = globalurl + "/includes/curl.php"; };
		if(lang == "en"){ submiturl = globalurl + "/includes/curl_en.php"; };
	 	$j.post(submiturl, {
			name: $j('input[name$="0[name]"]').val(),
			email: $j('input[name$="0[email]"]').val(),
			age: ageval,
			sex: sexval,
			oftsport: oftsportval
			},
	   function(data){
		   if(data){
				//alert(data);
		   }
	   });
		$j('.trainingform fieldset.right').show();
		if(ie == true){
			$j('.trainingform').width('625');
			$j('.block.fb').hide();
			$j('.closebutton').show();
			$j('#facebookshare').show();
			$j('.trainingform a.fsubmit').fadeOut();
			}
		else{
		$j('.hasform').animate({
			width: '625px'
		  }, 500, function() {
			$j('.closebutton').show();
			$j('#facebookshare').show();
		  });
		  $j('.trainingform a.fsubmit').fadeOut();
		}
		  
		};
		return false;
	});
	//Load the slideshow
	theRotator();
	$j('#sidebar.video').fadeIn(1000);
    $j('#sidebar.video ul li').fadeIn(1000); // tweek for IE
});
