$(function() {
/*
	var wrapHeight = $(document).height();
	$("body.portada #wrap").css('min-height', wrapHeight+'px');
*/
	jQuery.event.add(window, "load", resizeFrame);
	jQuery.event.add(window, "resize", resizeFrame);
	
	function resizeFrame() 
	{
		var h = $(window).height();
		$("body.portada #wrap").css('height',h+'px');
	}

	$(".external").attr("target","_blank");
	
	$("#lang").hover(function () {
		$("#lang").addClass("active");
		$("#lang a").addClass("active");
	},
	function () {
		$("#lang").removeClass("active");
		$("#lang a").removeClass("active");
	});
	
	$("#lang a").hover(function () {
		$("#lang").addClass("active");
		$("#lang a").addClass("active");
		$(this).removeClass("active");
	},
	function () {
		$("#lang").removeClass("active");
		$("#lang a").removeClass("active");
	});
	
	// set opacity on page load
	$("#menu span").css("opacity","0");
	// on mouse over
	$("#menu span").hover(function () {
		$(this).stop().animate({opacity: 1}, 75);
	},
	// on mouse out
	function () {
		$(this).stop().animate({opacity: 0}, 125);
	});


	//load image capture
	$("div.video").each(function(i){
		$(this).css("background-image","url(../img/motion/"+ $(this).attr("id") +".jpg)");
	});

	//rollover video captura
	$("div.video").hover(function () {
		$(this).children("div").fadeIn(350);
	},
	// on mouse out
	function () {
		$(this).children("div").fadeOut(200);			
	});


	$("div.play").click(function(){
		//div superior amb la imatge del video
		var vidImg = $(this).parent(".video");
		//id del video a Vimeo
		var vidID = $(vidImg).attr("rel");
		//div on insertar el codi HTML del video
		var vidTarget = $(vidImg).attr("id");
		//codi HTML del video
		/*
		var vidCode = '<object width="640" height="360"> \n' +
		'<param name="allowfullscreen" value="true" /> \n' +
		'<param name="allowscriptaccess" value="always" /> \n' +
		'<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+ vidID +'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1&amp;autoplay=1&amp;loop=1" /> \n' +
		'<embed src="http://vimeo.com/moogaloop.swf?clip_id='+ vidID +'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1&amp;autoplay=1&amp;loop=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="360"></embed> \n' +
		'</object> \n';
		*/
		var vidCode = '<iframe src="http://player.vimeo.com/video/'+ vidID +'?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="640" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> \n';
		$(this).replaceWith(vidCode);
	});

	//imatge croporativa
	$(".imgcorp #content a").each(function(i){
		$(this).css("background","url(http://www.adzavara.com/img/imatge-corporativa/"+ $(this).attr("id") +"_intro.jpg) no-repeat 0 0");
	});

	//rollover
	$(".imgcorp #content a").hover(function () {
		$(this).css("background-position","0 -140px");
	},
	// on mouse out
	function () {
		$(this).css("background-position","0 0");
	});

});
