jQuery(function($)
{
	Cufon.replace('#menu li a.cufon, #case_text h2, .team_image .functie, #cases_home_big .case_text, #team_image_2011 .name', {fontFamily: 'Cachet Std', hover: true});
	Cufon.replace('.title h1, .title h2, .title h3, #cases_home_big .case_title, .content-tab-label-text, .b-title, .werkoverzicht_list h2', {fontFamily: 'Cachet Bold'});


	$.fn.bgAnimate = function($x, $y, $dur) {
	
		$(this).css({ backgroundPosition: "0 0" })
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:'('+$x+ ' ' + $y + ')'}, {duration:$dur})
			console.log($dur);
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:$dur })
		})
	
	}
	
	$('#fbwall').fbWall({id:'webvaluebv',accessToken:'206158599425293|e8c822e89f25f6a825e729db.1-1256165932|Ykq24A-EFMRQwG7mvIuH5zSDiFM',showGuestEntries:true,showComments:false,max:10,timeConversion:24});
	
	/*$("#home_ons_werk .case, #werkoverzicht_holder .case").bgAnimate('0', '-200px', 150);
	$("#sidebar .case").bgAnimate('0', '-215px', 150);
	$(".subblock.click").bgAnimate('0', '-311px', 150);*/

	$('#cases_home_big').cycle({ 
	    //next:		'.next',
		timeout:	8000,
		random:		false,
		fx:			'scrollLeft',
		slideExpr:	'.case_slide',
		pager:		'#cases_home_nav'
	});
	
	$('#case_imgs_big').cycle(
	{
		pager:  	'#case_img_nav_inner',
		next:		'#case_img_overlay_top',
		slideExpr:	'.gallery_item',
		fx:			'scrollLeft',
		timeout:	5000,
		speed:		750
	});	
	
	$(".team_image .person").hover(
		function()
		{
			$(this).find('.more-info').stop(true, false).animate({ height: $(this).find('.more-info-inner').height() }, 200);
		},
		function(){
			$(this).find('.more-info').stop(true, false).animate({ height: "0" }, 200);
		}
	);
	
	$(".team_image .person").click(
		function()
		{
			$(this).find('.more-info').stop(true, false).animate({ height: $(this).find('.more-info-inner').height() }, 200);
		},
		function(){
			$(this).find('.more-info').stop(true, false).animate({ height: "0" }, 200);
		}
	);

	$('select#branches-menu').change(function()
	{
		var $value = $(this).val();
		if ($value != 'disabled') {
			$.get('/cmsfiles/operators/branche_switch.php', {'branche': $value}, function()
			{
				self.location.reload();
			});
		}
	});
	
	
	$('#branches-submenu-holder select').change(function()
	{
		var $value = $(this).val();
		if ($value != 'disabled') {
			$.get('/cmsfiles/operators/product_switch.php', {'product': $value}, function()
			{
				self.location.reload();
			});
		}
	});
	
		
	$('.werkoverzicht_list .branches li a').click(function(e)
	{
		var $value = $(this).attr('rel');
		$.get('/cmsfiles/operators/branche_switch.php', {'branche': $value}, function()
		{
			self.location.reload();
		});

		e.preventDefault();
	});
	
	$('.werkoverzicht_list .products li a').click(function(e)
	{
		var $value = $(this).attr('rel');
		$.get('/cmsfiles/operators/product_switch.php', {'product': $value}, function()
		{
			self.location.reload();
		});

		e.preventDefault();
	});
	
	$('#search_work input').click(function(){
		$inputvalue = $(this).val();
		if ($inputvalue == 'zoeken in werk') {
			$(this).val('');
		}
	});
	
	$('#search_work input').focusout(function(e) {
		$inputvalue = $(this).val();
		if ($inputvalue == '') {
			$(this).val('zoeken in werk');
		}
	});
	
	
	var code = null;
	$("#search_work input").keypress(function(e)
	{
		$value = $(this).val();
		if ($value != '') {
			code= (e.keyCode ? e.keyCode : e.which);
			if (code == 13) {
				$.ajax({
					type: 'POST',
					url: "/cmsfiles/operators/search_work.php",
					data: ({search_work : $value}),
					success: function(html){
						$("#werkoverzicht_holder_inner").hide();
						$("#search_work_results").html(html);
						$("#search_work_results").show();
					}
				}); 
			}
		}
	});
	
	$("#search_work a").click(function(e){
		$value = $("#search_work input").val();
		
		if ($value != '') {
			$.ajax({
				type: 'POST',
				url: "/cmsfiles/operators/search_work.php",
				data: ({search_work : $value}),
				success: function(html){
					$("#werkoverzicht_holder_inner").hide();
					$("#search_work_results").html(html);
					$("#search_work_results").show();
				}
			}); 
		}
		e.preventDefault();
	});
	
	
	
	$(".remove-results").live('click', function(e){
		$("#search_work_results").hide();
		$("#werkoverzicht_holder_inner").show();
		e.preventDefault();
	});
	
	
	
	$('#remove-session a').click(function(e)
	{
		$link = $(this).attr('href');

		$.get('/cmsfiles/operators/remove_session.php', function()
		{
			if ($link == '#') {
				self.location.reload();
			} else {
				self.location = $link;
			}
		});
		e.preventDefault();
	});
		
	$(".mailform .set-checked input").attr('checked','checked');

	
	$(".form_submit").click(function(e)
	{
		var form = $(this).parents('form');
	
		$(form).submit();
		e.preventDefault();
	});
	
	$targetWidth = $("#case_text .caselink.red span").width();
	$("#case_text .caselink span").width($targetWidth);
	
	$("#showIntro a").click(function(){
		$.cookie("webvalue_previous_visit", "");
	});
	
	$('#case_scroll').jScrollPane({
		showArrows: true
	});
		
	//PRELOAD
	var image_objs = new Array();
	var image_urls = new Array
	(
		"/images/opbouw/show_case_btn_ro.png",
		"/images/opbouw/next_case_btn_ro.png",
		"/images/opbouw/home_head_red_ro.gif",
		"/images/opbouw/home_head_blue_ro.gif",
		"/images/opbouw/home_head_gray_ro.gif",
		"/images/opbouw/home_contact_gesprek_ro.gif",
		"/images/opbouw/home_contact_offerte_ro.gif",
		"/images/opbouw/home_contact_contact_ro.gif",
		"/images/opbouw/bg_news_ro.gif",
		"/images/opbouw/bg_case_ro.gif",
		"/images/opbouw/vervolg_ons-werk_block_ro.gif",
		"/images/opbouw/vervolg_contact_gesprek_ro.gif",
		"/images/opbouw/vervolg_contact_contact_ro.gif",
		"/images/opbouw/vervolg_contact_offerte_ro.gif",
		"/images/opbouw/case_img_dot_ro.png",
		"/images/opbouw/case_link_ro.gif",
		"/images/opbouw/case_link_blue.gif",
		"/images/opbouw/case_link_blue_ro.gif",
		"/images/opbouw/case_nextbtn_ro.gif",
		"/images/opbouw/case_backbtn_ro.gif",
		"/images/opbouw/case_overzichtbtn_ro.gif",
		"/images/opbouw/arrow_black_link.gif"
	);
	
	var iL = image_urls.length;
	for(var i=0; i<iL; i++)
	{
		image_objs[i] = new Image();
		image_objs[i].src = image_urls[i];
	}
	
	TabController.activate();
});

