$(document).ready(function(){

	
	/*
	function randomXToY(minVal,maxVal,floatVal)
	{
	  var randVal = minVal+(Math.random()*(maxVal-minVal));
	  return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
	}
	*/


	///// PAUSE
	
	$.fn.pause = function(duration){
 		$(this).animate({ dummy: 1 }, duration);
 		return this;
	};
	
	
	///// LAYOUT
	
	//$("#content_wrapper .content_left .justify").characterJustify();
	
	//$("#sidebar_wrapper .justify").characterJustify();
	
	$('.content_text').columnize({width:175});
	
	/*
	$('div.column').each(function(){
		var current_txt = $(this).text();
		$(this).html(current_txt+' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
	});
	*/

	$('.content_left .content_header').css({height:$('.content_left .content_header').height()-15+'px'});
	$('.content_left .content_text .info').css({height:$('.content_left .content_text .info').height()-15+'px'});
	
	$('.carousel_row .carousel_item:last-child').find('p').css({borderBottomWidth:'1px',borderBottomStyle:'solid',borderBottomColor:'#cfccca'});
	
	
	///// ZOEK FOCUS

	$(".search").focus(function(){
		if(this.value=='SEARCH'){
			this.value='';
			this.style.color='#414141';
		} else {
			this.style.color='#414141';
		}
	});
	$(".search").blur(function(){
		if(this.value==''){
			this.value='SEARCH';
			this.style.color='#999999';
		} else if(this.value=='SEARCH'){
		this.style.color='#999999';
		} else {
			this.style.color='#414141';
		}
	});
	
		
	///// 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();
 	});
 	
 	
 	///// NAV DROP
 	
 	$('div.nav_item').hover(function(){
 		$('div.drop[id="'+$(this).attr('rel')+'"]').show();
 	},function(){
 		$('div.drop[id="'+$(this).attr('rel')+'"]').hide();
 	});
 	
 	
 	$('div.drop').each(function(){
 	
 		var new_width = $('h1.drop[id="'+$(this).attr('id')+'"]').width() + 15;
 		$(this).css({width:new_width+'px'});
 	
 	});
 	
 	
 	///// CONTENT IMAGE
 	
 	$('.content_right .content_image').each(function(index){
 		$('img',this).load(function(){
 			$(this).css({height:$(this).height()+'px'});
 		});
 		//$(this).css({height:$('img',this).height()+'px'});
 	});
 	
 	
 	///// FOOTER
 	
 	$(window).load(function(){
 		$('#footer_wrapper').css({top:$(document).height()-$('#footer_wrapper').height()+25+'px'}).show();
 	});
 	
 	$('#footer span#top').click(function(){
 		$('html,body').animate({scrollTop:0},'slow');
 	});
 	
 	$('#footer span#sitemap').click(function(){
 		
 		//var cur_top = $('div#footer_wrapper').css('top').replace("px","");
 		//var new_top = cur_top - $('div#sitemap').height();

 		$('div#sitemap').toggle(150);
 		//$('div#footer_wrapper').animate({top:new_top+"px"},'fast');
 		$('html,body').animate({scrollTop:$(document).height()},'150');
 	});
 	
 	
 	///// CAROUSEL
	
 	$('.carousel_row').cycle({
		fx:     'scrollHorz',
		speed:   600,
		timeout: 0,
		random:  0,
		startingSlide: $('.carousel_row_active').attr('id'),
		prev:   '#carousel_prev',
		next:   '#carousel_next',
		pager:  '#carousel_nav',
		pagerAnchorBuilder: function(idx, slide) {
				return '#carousel_nav li:eq(' + (idx) + ') a';
		}
	}); 	
 		
	///// 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'
		});
		
	});            
	
});
