///// 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(){
	
	///// PAUSE
	
	$.fn.pause = function(duration){
 		$(this).animate({ dummy: 1 }, duration);
 		return this;
	};
	
	///// TWITTER
	
	$("#twitter").getTwitter({
		userName: "KinAssurantien",
		numTweets: 3,
		loaderText: "Loading tweets...",
		slideIn: false,
		showHeading: false,
		headingText: "Tweets",
		showProfileLink: false
	});
	
	
	
	$("a.file[id!='']").click(function(event){
		event.preventDefault();
		$("div.overlay_container[id="+this.id+"]").fadeIn(250);
	});
	
	$("div.overlay_container").click(function(event){
		$(this).fadeOut(250);
	});
	
	///// RADIO
 
	 $("#radio li").click(function(event){
		event.preventDefault();
		$('#radio > li').removeClass("active");
		var id = this.id;
		var newselect = id.replace('-li-', '-');
		$('#'+newselect).attr('checked', true);
		$(this).addClass("active");
		$(this).parent().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);
	
 	///// LINK SCROLL
 	
	$("#left .link").click(function(){
	  var offset = $("#right div[id='scroll_"+$(this).attr('id')+"']").offset();
	  var offset_top = offset.top - 15;
	 	$('html,body').animate({scrollTop: offset_top}, 500);
	});
	
	if(window.location.hash){
	//	var hash = window.location.hash.replace("#","");
	//	var offset2 = $("#content_wrapper .right a[name='"+hash+"']").offset();
	//  var offset_top2 = offset2.top - 15;
	// 	$('html,body').animate({scrollTop: offset_top2}, 500);
	}
 	
 	
 	///// CAROUSEL
 	
 	$('.carousel_header_container').cycle({
		fx:     'fade',
		speed:   1000,
		timeout: 7500,
		random:  0,
		pager:  '.carousel_header_nav',
		pagerAnchorBuilder: function(idx, slide) {
				return '.carousel_header_nav li:eq(' + (idx) + ') a';
		}
	});
	
	$('.carousel_container').cycle({
		fx:     'fade',
		speed:   1000,
		timeout: 0,
		random:  0,
		prev:   '#carousel_prev',
		next:   '#carousel_next'
	});
 	/*
 	$('.carousel_row').cycle({
		fx:     'scrollVert',
		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').setAllToMaxHeight();
 	
	///// 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'
		});
		
	});
	
	
});
