jQuery(document).ready(function($){
		
	var $container = $('#wrapper');
    
	$container.masonry({
		itemSelector: '.box',
		columnWidth: 5,
		isAnimated: false,
		animationOptions: {
			duration: 150,
			easing: 'swing',
			queue: true
		}
	});
		
	jQuery(".tooltip").simpletooltip();

	function initPrettyPhoto(){
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animationSpeed: 'fast',
			opacity: 0.6,
			showTitle: false,
			social_tools: false
		});	
		$("a[rel^='prettyFrame']").prettyPhoto({
			animationSpeed: 'fast',
			opacity: 0.6,
			showTitle: false,
			default_width: 640,
			default_height: 480,
			social_tools: false,
			theme: 'dark_square',
			markup: '<div class="pp_pic_holder"> \
						<div class="ppt">&nbsp;</div> \
						<div class="pp_top"> \
							<a class="pp_close" href="#">Close</a> \
						</div> \
						<div class="pp_content_container"> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_loaderIcon"></div> \
									<div class="pp_fade"> \
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
										<div class="pp_hoverContainer"> \
											<a class="pp_next" href="#">next</a> \
											<a class="pp_previous" href="#">previous</a> \
										</div> \
										<div id="pp_full_res"></div> \
										<div class="pp_details"> \
											<div class="pp_nav"> \
												<a href="#" class="pp_arrow_previous">Previous</a> \
												<p class="currentTextHolder">0/0</p> \
												<a href="#" class="pp_arrow_next">Next</a> \
											</div> \
											<p class="pp_description"></p> \
											{pp_social} \
										</div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
						<div class="pp_bottom"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
					</div> \
					<div class="pp_overlay"></div>'
		});  
	}
	initPrettyPhoto();
	
	jQuery.fn.setAllToMaxHeight = function(){
		return this.height( Math.max.apply(this, jQuery.map( this , function(e){ return jQuery(e).height()}) ) );
	}

	$('.nav').setAllToMaxHeight();
	$('.listcontent a').fadeInOut();
 
});



(function($){	
	$.fn.setVideoSize = function() {
		var $vw = $(this).width();
		var $vr = 0;
		if($(this).hasClass('widescreenratio')){
			$vr = 1.75;
		}
		if($(this).hasClass('normalratio')){
			$vr = 1.33;
		}
		if($(this).hasClass('letterboxratio')){
			$vr = 2.35;
		}
		$vh = $vw / $vr;
		$vhInt = Math.round($vh);
		$(this).css({'height': $vhInt +'px', 'marginBottom':'20px'});		
	};
})(jQuery);


(function($){	
	$.fn.fadeInOut = function(width) {
	
	$(this).hover(function(){
		$(this).find('.popup_readmore').stop().animate({'opacity':1,'top':130},200, 'easeInOutSine');
//		$(this).find('img').stop().animate({'opacity':'.5'},200, 'easeInOutSine');
		$(this).find('.imgbox').css({'background-image':'none'});
		},function(){
			$(this).find('.popup_readmore').stop().animate({'opacity':0,'top':0},600, 'easeInOutSine');
//			$(this).find('img').stop().animate({'opacity':'1'},600, 'easeInOutSine');								  
		});				
	};
})(jQuery);

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions


// OPEN LINKS IN NEW WINDOW
jQuery(function() {
	jQuery('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});
});

// JavaScript Document

/* 
 * Cross-browser event handling, by Scott Andrew
 */
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 *
 * by Ross Shannon, http://www.yourhtmlsource.com/
 */

addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}

/**
*
*	simpleTooltip jQuery plugin, by Marius ILIE
*	visit http://dev.mariusilie.net for details
*
**/
(function(jQuery){ jQuery.fn.simpletooltip = function(){
	return this.each(function() {
		var text = jQuery(this).attr("title");
		jQuery(this).attr("title", "");
		if(text != undefined) {
			jQuery(this).hover(function(e){
				var tipX = e.pageX + 12;
				var tipY = e.pageY + 12;
				jQuery(this).attr("title", ""); 
				jQuery("body").append("<div id='simpleTooltip' style='position:absolute; z-index: 9999; display: none; font-size: 10px;font-family:ClarendonLTStdLight,Georgia,serif;'>" + text + "</div>");
				if(jQuery.browser.msie) var tipWidth = jQuery("#simpleTooltip").outerWidth(true)
				else var tipWidth = jQuery("#simpleTooltip").width()
				jQuery("#simpleTooltip").width(tipWidth);
				jQuery("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
			}, function(){
				jQuery("#simpleTooltip").remove();
				jQuery(this).attr("title", text);
			});
			jQuery(this).mousemove(function(e){
				var dondeEstaElElem = jQuery(this).offset();
				if(dondeEstaElElem.top >= 50) {
					var tipX = e.pageX - 10;
					var tipY = e.pageY - 30;
					var tipWidth = jQuery("#simpleTooltip").outerWidth(true);
					var tipHeight = jQuery("#simpleTooltip").outerHeight(true);
				} else {
					var tipX = e.pageX + 10;
					var tipY = e.pageY + 20;
					var tipWidth = jQuery("#simpleTooltip").outerWidth(true);
					var tipHeight = jQuery("#simpleTooltip").outerHeight(true);
				}
				
				if(tipX + tipWidth > jQuery(window).scrollLeft() + jQuery(window).width()) tipX = e.pageX - tipWidth;
				if(jQuery(window).height()+jQuery(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
				jQuery("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
			});
		}
	});
}})(jQuery);


jQuery(document).ready(function($) {
	$('a[title]').simpletooltip();
	
	$('.close').hide();
	$(document).delegate(".listcontent a.ajaxlink", "click", function() { 
//		$(this).animate({'opacity':'0.5'},200,function(){
		$('.openbox').animate({'opacity':'0.5'},200,function(){
			$('.close',this).hide();
			$('.postloader',this).empty();	
			$(this).css({'width':'200px'});
			$(this).delay(200).animate({'opacity':'1'},500, function(){																			
				$('.listcontent',this).fadeIn('fast');																					  
				$('#wrapper').delay(200).masonry();					
			});
			$('.openbox').removeClass('openbox');
		});																			 
       	url = $(this).attr('href');
		$(this).parent('.listcontent').fadeOut(300,function(){
			$(this).parent('.portfoliobox').animate({'width':'610px','marginRight':'5px'},0,function(){
				$(this).find('.postloader').load(url + " #loadframe", function() {
					$(document).scrollTo($(this).parent('.portfoliobox'),300,{offset:-5},'easeInOut');
					$(this).parent().find('.close').fadeIn();																						 
					$('#wrapper').masonry();
					$('#inlinegallerylist li a').fadeInOut();
					$("a[rel^='prettyPhoto']").prettyPhoto({
						animationSpeed: 'fast',
						opacity: 1,
						showTitle: true
					});	
					$('.questgallery').questGallery();
						$(this).delay(500).animate({'opacity':'1'},200,function(){
						});		
					});		
					$(this).addClass('openbox');																								 
				}); 												 
			});
 			return false; 
		});
		
		$('.close').click(function(){
			$(this).parent('.portfoliobox').animate({'opacity':'0.5'},200,function(){
				$(this).removeClass('openbox');
				$('.close',this).hide();
			  	$('.postloader',this).empty();	
			  	$(this).css({'width':'200px'});
			  	$(this).delay(200).animate({'opacity':'1'},500, function(){
					$('.listcontent',this).fadeIn('fast');																					  
					$('#wrapper').delay(200).masonry();
				});		
			}); 
		return false;						
		});
		
		// chumbeque con el menu
		$('#btn_clientes').click(function(e){
			e.preventDefault();
			$('#Clientes:not(:hidden)').find('.ajaxlink').click();
			$('#nav_principal li a').removeClass('selected');
			$(this).addClass('selected');
			
		});
		$('#nosotros').click(function(e){
			e.preventDefault();
			$('#Nosotros:not(:hidden)').find('.ajaxlink').click();
			$('#nav_principal li a').removeClass('selected');
			$(this).addClass('selected');
		});
		$('#btn_portfolio').click(function(e){
			e.preventDefault();
			$('.box .close:visible').click();
			$('#nav_principal li a').removeClass('selected');
			$(this).addClass('selected');
		});
		
/*		$('#btn_elequipo').click(function(e){
			e.preventDefault();
			$('#El Equipo').find('.ajaxlink').click();
		});*/
		
		// cosita de premios en el header
		$('.premios_btn').click(function(){
				$('#premios').animate({'top':0},'slow');
			});
		$('#premios').click(function(){
			$(this).animate({'top':-212},'fast');
		});

});
