///// CHECKBOX
	
function checkbox(inputId,aId,varOn){
	if(document.getElementById(inputId).value == 'n'){
		document.getElementById(inputId).value = 'y';
		document.getElementById(aId).className = 'check_y';
	} else {
		document.getElementById(inputId).value = 'n';
		document.getElementById(aId).className = 'check_n';
	}
}


$(document).ready(function(){

	///// SELECT DATE
	
	$('select[name="blog_year"],select[name="blog_month"]').change(function() {
		
		$(this).closest("form[name='select_date']").submit();
		  	
	});


	///// CAPTCHA

	$('input[name=captcha]').focus(function(){
		if(this.value=='(typ de code over)'){
			this.value='';
			this.style.color='#000000';
		} else {
			this.style.color='#000000';
		}
	});
	$('input[name=captcha]').blur(function(){
		if(this.value==''){
			this.value='(typ de code over)';
			this.style.color='#ffffff';
		} else if(this.value=='(typ de code over)'){
			this.style.color='#ffffff';
		} else {
			this.style.color='#000000';
		}
	});
	
	///// SOCIAL MEDIA
	
	$('a.social span').css('opacity',0.5);
	
	if($.browser.msie){
		$('a.social').hover(function(){
	 		$('span',this).css({ opacity:0});
	 	},function(){
	 		$('span',this).css({ opacity:0.5});
	 	});
	} else {
		$('a.social').hover(function(){
	 		$('span',this).stop().animate({ opacity:0}, 200);
	 	},function(){
	 		$('span',this).stop().animate({ opacity:0.5}, 200);
	 	});
 	}
 	
 	///// ROUTE
	
	$('a.route span').css('opacity',0);
	
	if($.browser.msie){
		$('a.route').hover(function(){
	 		$('span',this).css({ opacity:1});
	 	},function(){
	 		$('span',this).css({ opacity:0});
	 	});
	} else {
		$('a.route').hover(function(){
	 		$('span',this).stop().animate({ opacity:1}, 200);
	 	},function(){
	 		$('span',this).stop().animate({ opacity:0}, 200);
	 	});
 	}
 	
 	///// OVERLAY
 	
 	$('.overlay_container').click(function(){
	 	$(this).fadeOut(250);
	});
	
	///// PAUSE
	
	$.fn.pause = function(duration){
 		$(this).animate({ dummy: 1 }, duration);
 		return this;
	};
	

	///// TWITTER
	
	$("#twitter").getTwitter({
		userName: "Blijf_Fit",
		numTweets: 3,
		loaderText: "Loading tweets...",
		slideIn: false,
		showHeading: false,
		headingText: "Tweets",
		showProfileLink: false
	});
	
	/*
	$('.image img').click(function(event){
		$('#large').fadeIn(400);
		$('.txt').animate({color:'#c0c0c0'});
	});
	
	$('#large').click(function(event){
		$('#large').fadeOut(400);
		$('.txt').animate({color:'#231f20'});
	});
	
	$('.txt').click(function(event){
		$('#large').fadeOut(400);
		$('.txt').animate({color:'#231f20'});
	});
	*/
	 	
 	///// FANCYBOX
 	
 	$("a.fancybox").fancybox({
 		'overlayOpacity'	:'0.6',
 		'overlayColor'		:'#d7d6db',
 		'hideOnContentClick'	:'true',
 		'titlePosition'	: 'inside'
 	});
	
	
	///// RADIO
 	
	$("#radio li").click(function(event){
		event.preventDefault();
		var id = this.id;
		var newselect = id.replace('-li-','-');
		$('input#'+newselect+'[rel="'+$(this).attr('rel')+'"]').attr('checked',true);
		$('#radio li[rel="'+$(this).attr('rel')+'"]').removeClass("active");
		$(this).addClass("active");
		return false;
	});
	
	var footer_offset = $("#footer_wrapper").offset();
	var content_offset = $("#content_wrapper").offset();
	var test = footer_offset.top - content_offset.top - 20;
	$('#content_wrapper #left').css({height:test+'px'});
	
	///// SOCIAL
	
	$('a.social_passive').css('opacity',0.3);
	
	///// MEMBERS
	
	var team_image_h = $('#team_image').height() - 10;
	$('#quotes').css({height:+team_image_h+'px'});
	
	if($('#team_members').length != 0){
 		var test = $('#content_wrapper .right').height() - 30;
		$('#content_wrapper .right').css({height:test+'px'});
	}
 	
	///// CAROUSEL
	
	$('.carousel_container_home').cycle({
		fx:     'fade',
		speed:   1500,
		timeout: 8000,
		random:  0,
		pager:  '#carousel_nav_home',
		pagerAnchorBuilder: function(idx, slide) {
				return '#carousel_nav_home li:eq(' + (idx) + ') a';
		}
	});
	
	$('.carousel_row').cycle({
		fx:     'fade',
		speed:   600,
		timeout: 0,
		random:  0,
		startingSlide: $('.carousel_row_active').attr('id'),
		prev:   '#carousel_prev',
		next:   '#carousel_next'
	});
	

	///// EQUAL HEIGHT & WIDTH
		
	$.fn.setAllToMaxHeight = function(){
		return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
	}
	
	$.fn.setAllToMaxWidth = function(){
		return this.width( Math.max.apply(this, $.map( this , function(e){ return $(e).width() }) ) );
	}
	
	$('.equal_h').each(function(){
 		$('div.left, div.center, div.right, div.line_v',this).setAllToMaxHeight();
 	});
 	 	
 	///// BLOG
 	
 	//var test = $('#blog_right').height();
 	//$('#blog').css({min-height:test+'px'});
		
	var new_h = $('#blog').height() + 20;
	$('#blog, #blog #blog_left, #blog #blog_right').css({height:new_h+'px'});
	

 	
 	///// LINK SCROLL
 	
	$("#content_wrapper .left .link").click(function(){
	  var offset = $("#content_wrapper .right h1[id='"+$(this).attr('id')+"']").offset();
	  var offset_top = offset.top - 15;
	 	$('html,body').animate({scrollTop: offset_top}, 500);
	});
	
 	
	///// JCROP IMAGE
	
	$('.jcrop_image').each(function(index){
	
		var jcrop_rel = $(this).attr("rel");
		var jcrop_vars = jcrop_rel.split(']-[');

		var rx = jcrop_vars[1] / jcrop_vars[7];
		var ry = jcrop_vars[2] / jcrop_vars[8];
					
		var jcrop_img_w = jcrop_vars[9];
		var jcrop_img_h = jcrop_vars[10];
				
		$(this).parent('.image_container').css({width:jcrop_vars[1]+'px',height:jcrop_vars[2]+'px'});
		
		$(this).css({
			width: Math.round(rx * jcrop_img_w) + 'px',
			height: Math.round(ry * jcrop_img_h) + 'px',
			marginLeft: '-' + Math.round(rx * jcrop_vars[3]) + 'px',
			marginTop: '-' + Math.round(ry * jcrop_vars[4]) + 'px'
		});
		
	});
	
	
});
