$(document).ready(function() {
    
	$('.textwidget .wpcf7-form p span input[type=text]').focus(function () { showHideInputValueContour($(this)) }).blur(function () { showHideInputValueContour($(this)) });
	$('.textwidget .wpcf7-form p span textarea').focus(function () { showHideInputValueContour($(this)) }).blur(function () { showHideInputValueContour($(this)) });
	$('.textwidget .wpcf7-submit').val('');
    
    	$('.subImg img').css({opacity:'0'});
	
	$(".subImg img").animate({opacity: "1" }, 1000);
	


	$(".menu1 ul li").prepend("<span></span>"); //Throws an empty span tag right before the a tag

	$(".menu1 ul li").each(function() { //For each list item...
		var linkText = $(this).find("a").html(); //Find the text inside of the <a> tag
		$(this).find("span").show().html(linkText); //Add the text in the <span> tag
	}); 

	$(".menu1 ul li").hover(function() {	//On hover...
		$(this).find("span").stop().animate({
			marginTop: "-40" //Find the <span> tag and move it up 40 pixels
		}, 250);
	} , function() { //On hover out...
		$(this).find("span").stop().animate({
			marginTop: "0"  //Move the <span> back to its original state (0px)
		}, 250);
	});

	//$('.feat_prev').click(function() {
		//$('.quickLinks ul li.active').next('li').removeClass('active');
	//	$('.quickLinks ul li.active').prev('li').addClass('active');
			
		
	//});

	loadFirstPerson();
	
	
	$(".personale .person").find('.photo').click(function(){
		// animere person ud
		$('.slideWrapper .descriptionWrapper').animate({
			//marginLeft: '+2000px'
		}, 500, slideOut(this));
	

/*		
		$('.slideWrapper').html('');
		$(".personale .person").removeClass('active');
		$(this).parent().addClass('active');
		//$(".personale .person").find('.selector').css({display:'none'})

		$(this).parent().find('.descriptionWrapper').clone().appendTo($('.slideWrapper'));
		
		// animere person ind
		$('.slideWrapper .hide').css({marginLeft:'-2000px'})
		$('.slideWrapper .hide').animate({
			marginLeft: '0px'
		}, 750, function() {
			//alert('animation complete');
		});
*/
	});
	
	/*
	$("ul.subItems li").hover(function(){
		$(this).stop().animate({
			marginLeft: "10" //Find the <span> tag and move it up 40 pixels
		}, 250);
	}, function() { //On hover out...
		$(this).stop().animate({
			marginLeft: "0"  //Move the <span> back to its original state (0px)
		}, 250);
	});
	
	
	$("#flexipages-2 ul li.current_page_ancestor ul li").hover(function(){
		$(this).stop().animate({
			marginLeft: "10" //Find the <span> tag and move it up 40 pixels
		}, 150);
	}, function() { //On hover out...
		$(this).stop().animate({
			marginLeft: "0"  //Move the <span> back to its original state (0px)
		}, 150);
	});
	
	$("#flexipages-2 ul li.page_item ul li").hover(function(){
		$(this).stop().animate({
			marginLeft: "10" //Find the <span> tag and move it up 40 pixels
		}, 150);
	}, function() { //On hover out...
		$(this).stop().animate({
			marginLeft: "0"  //Move the <span> back to its original state (0px)
		}, 150);
	});
	*/

	$('#portfolio-list').filterable();
	
	
	$('#mycarousel').jcarousel({
		scroll:1,
		animation:'slow'
	});
	
	
	




	
	
	
// Next & prev ----------------------------------------------------------------------------------------	
	$(".jcarousel-prev").hover(function(){
		$(this).stop().animate({
			marginLeft: "-5" //Find the <span> tag and move it up 40 pixels
		}, 150);
	}, function() { //On hover out...
		$(this).stop().animate({
			marginLeft: "0"  //Move the <span> back to its original state (0px)
		}, 150);
	});

	
	$(".jcarousel-next").hover(function(){
		$(this).stop().animate({
			marginRight: "-5" //Find the <span> tag and move it up 40 pixels
		}, 150);
	}, function() { //On hover out...
		$(this).stop().animate({
			marginRight: "0"  //Move the <span> back to its original state (0px)
		}, 150);
	});
	 


	 
// Next & prev ----------------------------------------------------------------------------------------
	
		
		
	$(".jcarousel-next-horizontal").click(function()
	{
		if($(".personale .person:last").hasClass('active')){
			// alert('dette er det sidste element')
			/*$('.slideWrapper').html('');
			
			$firstElem = $('.personale').find('.active');
			$firstElem.parent().find('li.person:first').addClass('active');
			$firstElem.removeClass('active');
			
			$('.personale').animate({
				left: '-151px'
			}, 750);

	
			$('.personale').parent().find('.active .descriptionWrapper').clone().appendTo($('.slideWrapper'));
			$('.slideWrapper .hide').css({marginLeft:'-2000px'})
			$('.slideWrapper .hide').animate({
				marginLeft: '0px'
			}, 750, function() {
				//alert('animation complete');
			});*/
			
	
		}
		else{

			
			
			$('.slideWrapper').html('');
	
			//$('.personale').animate({
			//	left: ''
			//}, 750);
			
			$nextElem = $('.personale').find('.active');
			$nextElem.next('li.person').addClass('active');
			$nextElem.removeClass('active');
	
			$('.personale').parent().find('.active .descriptionWrapper').clone().appendTo($('.slideWrapper'));
			$('.slideWrapper .hide').css({marginLeft:'-2000px'})
			$('.slideWrapper .hide').animate({
				marginLeft: '0px'
			}, 750, function() {
				//alert('animation complete');
			});
		}
		

	});
	
	$(".jcarousel-prev-horizontal").click(function()
	{
		if($(".personale .person:first").hasClass('active')){
			 //alert('dette er det sidste element')	
		}
		else{
			$('.slideWrapper').html('');
	
			$prevElem = $('.personale').find('.active');
			$prevElem.prev('li.person').addClass('active');
			$prevElem.removeClass('active');
		
			
			$('.personale').parent().find('.active .descriptionWrapper').clone().appendTo($('.slideWrapper'));
			$('.slideWrapper .hide').css({marginLeft:'-2000px'})
			$('.slideWrapper .hide').animate({
				marginLeft: '0px'
			}, 750, function() {
				//alert('animation complete');
			});
		}
	});
	
	
	 
	 
	$('.previewImage').hover(function() {

		$(this).find('.attachment-thumbnail').stop().animate({
			marginTop:'-109'	
		},100);
		}, function() {
		$(this).find('.attachment-thumbnail').stop().animate({
			marginTop:'0'	
		},200);
	});



	// create custom animation algorithm for jQuery called "drop" 
	$.easing.drop = function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	};
	
	
		// loading animation
	$.tools.overlay.addEffect("drop", function(css, done) { 
	   
	   // use Overlay API to gain access to crucial elements
	   var conf = this.getConf(),
	       overlay = this.getOverlay();           
	   
	   // determine initial position for the overlay
	   if (conf.fixed)  {
	      css.position = 'fixed';
	   } else {
	      css.top += $(window).scrollTop();
	      css.left += $(window).scrollLeft();
	      css.position = 'absolute';
	   } 
	   
	   // position the overlay and show it
	   overlay.css(css).show();
	   
	   // begin animating with our custom easing
	   overlay.animate({ top: '+=55',  opacity: 1,  width: '+=20'}, 400, 'drop', done);
	   
	   /* closing animation */
	   }, function(done) {
	      this.getOverlay().animate({top:'-=55', opacity:0, width:'-=20'}, 300, 'drop', function() {
		 $(this).hide();
		 done.call();      
	      });
	   }
	);
	
	$("nav a[rel]").overlay({
		effect: 'drop',
		mask: '#4c4c4c'

	});
	

	/*	
	if ($('.quickMenu').length >= 0){
		var mystring = $('.quickMenu ul li.first a').html();
		var firstword = mystring.replace(/(^\w+)/,'<strong>$1</strong>');
		$('.quickMenu ul li.first a').html(firstword);
	
		var mystring = $('.quickMenu ul li.second a').html();
		var firstword = mystring.replace(/(^\w+)/,'<strong>$1</strong>');
		$('.quickMenu ul li.second a').html(firstword);
		
		var mystring = $('.quickMenu ul li.third a').html();
		var firstword = mystring.replace(/(^\w+)/,'<strong>$1</strong>');
		$('.quickMenu ul li.third a').html(firstword);
		
		var mystring = $('.quickMenu ul li.fourth a').html();
		var firstword = mystring.replace(/(^\w+)/,'<strong>$1</strong>');
		$('.quickMenu ul li.fourth a').html(firstword);
	}
	*/
	fixPNGs();
	
	$(".hide_fb_like a iframe").css('width','auto');
	

});



function fixPNGs(){
  if(jQuery.browser.msie && jQuery.browser.version < 9){ 
 var i;
 //alert(document.images.length);
 for(i in document.images){
   if(document.images[i].src){
  var imgSrc = document.images[i].src;
  if(imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG'){
  document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
  }
   }
 } 
  }
}





function loadFirstPerson () {
	$(".personale :first.person").addClass('active');
	$(".personale :first.person").find('.descriptionWrapper').clone().appendTo($('.slideWrapper'));
	//$(".personale :first.person").prepend('<img class="selector" src="http://localhost/brinthoghillerup/wp-content/themes/brinthoghillerup/images/selector.png" />');
};

function findPerson (elem) {
	$('.slideWrapper').html('');
	$(".personale .person").removeClass('active');
	$(elem).parent().addClass('active');
	//$(".personale .person").find('.selector').css({display:'none'})

	$(elem).parent().find('.descriptionWrapper').clone().appendTo($('.slideWrapper'));
	
	//$(elem).parent().find('.descriptionWrapper').clone().prependTo($('.slideWrapper'));
	
	// animere person ind
	$('.slideWrapper .hide').css({marginLeft:'-100%'})
	$('.slideWrapper .hide').animate({
		marginLeft: '0px'
	}, 400, function() {
		//alert('animation complete2');
	});
	
};

function slideOut (elem) {
	// animere person ind
	//$('.slideWrapper .hide').css({margin:'0 0 0 0'})
	$('.slideWrapper .hide').animate({
		marginLeft: '+100px',
		opacity:'0.0'
	}, 175, function() {
		findPerson(elem);
	});	
};



function showHideInputValueContour(argObj) {
    if ($(argObj).val() == $(argObj).parent().parent().prev().html())
        $(argObj).val('')
    else if ($(argObj).val() == "")
        $(argObj).val($(argObj).parent().parent().prev().html())
}
