$(document).ready(function(){
	
	///// PAUSE
	
	$.fn.pause = function(duration){
 		$(this).animate({ dummy: 1 }, duration);
 		return this;
	};
	
	///// FRAME
	
	var frame_top = ($(window).height() - 550) / 2;
	$('#frame').css({top:frame_top+'px'});
	$('#comments_container').css({top:frame_top+60+'px'});
	
	$(window).resize(function(){
  	var frame_top = ($(window).height() - 550) / 2;
  	if(frame_top > 0){
			$('#frame').css({top:frame_top+'px'});
			$('#comments_container').css({top:frame_top+60+'px'});
		}
	});
	
	//$("#frame").draggable({containment:"#container",scroll:false});
	
	
	///// NAV
	
	if(!$.browser.msie){
		$('#nav a, #footer a.social').css('opacity',0.75);
		$('#nav a[class!="passive"], #footer a.social').hover(function(){
	 		$(this).stop().animate({ opacity:1}, 200);
	 	},function(){
	 		$(this).stop().animate({ opacity:0.75}, 200);
	 	});
 	}
 	
 	///// INFO
	
	if($.browser.msie){
		$('#nav a#info').click(function(){
	 		$('.info').toggle();
	 	});
	} else {
		$('#nav a#info').click(function(){
	 		if($('.info').is(':visible')){
	 			$('.info').fadeOut(200);
	 		} else {
	 			$('.info').fadeIn(200);
	 		}
	 	});
 	}
 	
 	///// COMMENTS
 	
 	//$('#comments').css({opacity:0});
 	$('.show_comments, #frame_content #comments_show').click(function(){
 		var e = $('#comments_container');
		if(e.css('marginLeft')!='-175px'){
 			$('#frame').animate({left:'0px'}, 500);
 			$('#comments_container').animate({marginLeft:'-175px'}, 500);
 		} else {
 			$('#comments_container').animate({marginLeft:'35px'}, 500);
 			$('#frame').animate({left:'-230px'}, 500);
 		}
 	});
	
	///// BACKGROUND
	
	$.fn.supersized.options = {  
		startwidth: 1024,  
		startheight: 748,
		vertical_center: 1,
		slideshow: 0,
		navigation: 0,
		transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
		pause_hover: 0,
		slide_counter: 1,
		slide_captions: 1,
		slide_interval: 3000
	};
  $('#supersize').supersized();
	
	var _preventDefault = function(evt) { evt.preventDefault(); };
	$("#supersize").bind("dragstart", _preventDefault).bind("selectstart", _preventDefault);
	
	///// 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;
	 });
	
	 	
	///// 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'
		});
		
	});
	
	
});
