
jQuery(document).ready(function($){

$('#colorswap a').click(function(){
			
			//deleteCookie('style');								
			var color = $(this).attr('title');								
			$('body').removeClass('black white light dark');
			$('body').addClass(color);	
			createCookie('style', color, 365);
			Cufon.refresh();
										
			});
var stylesheet = readCookie('style');
if(stylesheet){
	$('body').addClass(stylesheet);
	}
		
var $container = $('#wrapper');
    
    
      $container.masonry({
        itemSelector: '.box',
        columnWidth: 10,
		  isAnimated: false,
		  animationOptions: {
    			duration: 150,
    			//easing: 'linear',
    			queue: true
  			}
	
      });
		
jQuery(".tooltip").simpletooltip();

function initPrettyPhoto(){
$("a[rel^='prettyPhoto']").prettyPhoto({
			animationSpeed: 'fast', /* fast/slow/normal */
			opacity: 1, /* Value between 0 and 1 */
			social_tools: false,
			overlay_gallery: false,
			showTitle: true /* true/false */
		});	  
}
 
 
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':'80px'},600, 'easeInOutSine');
				$(this).find('img').stop().animate({'opacity':'.5'},600, 'easeInOutSine');
				$(this).find('.imgbox').css({'background-image':'none'});
				},function(){
					$(this).find('.popup_readmore').stop().animate({'opacity':'0','top':'0px'},500, '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;'>" + 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 tipX = e.pageX - 10;
				var tipY = e.pageY - 40;
				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($) {
	
$('.close').hide();
	
 $(document).delegate(".listcontent a.ajaxlink", "click", function() { 
		
		
			
			$('.openbox').animate({'opacity':'0.5'},200,function(){
					  $('.close',this).hide();
					  $('.postloader',this).empty();
					  	
					  $('.openbox').css({'width':'200px'});
					  $('.openbox').delay(200).animate({'opacity':'1'},500, function(){
																									
							$('.listcontent',this).fadeIn('fast');																					  
							$('#wrapper').delay(200).masonry();
									
							});
					  
					  $('.openbox').removeClass('openbox');
						
				});
			
			
			
			/*$('.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').css({'width':'200px'});																					  
							$('#wrapper').delay(200).masonry();
									
							});	
						
				}); */
			
													  
		
																						 
       url = $(this).attr('href');
		 
		$(this).parent('.listcontent').fadeOut(300,function(){
					$(this).parent('.portfoliobox').addClass('openbox');												 
					$(this).parent('.portfoliobox').animate({'width':'640px','marginRight':'20px'},0,function(){
				
					$(this).find('.postloader').load(url + " #loadframe", function() {
						$(document).scrollTo( $(this).parent('.portfoliobox'),300,{offset:-20},'easeInOut'  );
						$(this).parent().find('.close').fadeIn();	
						//var cheight = $(this).height();
						//$(this).css({'opacity':'0','height':cheight +'px'});																						 
						$('#wrapper').masonry();
						Cufon.refresh();	
						
						$('#inlinegallerylist li a').fadeInOut();
						$("a[rel^='prettyPhoto']").prettyPhoto({
									animationSpeed: 'fast', /* fast/slow/normal */
									opacity: 1, /* Value between 0 and 1 */
									showTitle: true /* true/false */
								});	
						$('.questgallery').questGallery();
						
								$(this).delay(500).animate({'opacity':'1'},200,function(){
										
					  	
									});		});																										 
				 }); 												 
			});
		
			
		
 			return false; 
 });
 
 
		
		$('.close').click(function(){
													 
				$(this).parent('.portfoliobox').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();
									
							});	
						
				}); 
	
			return false;
											
			});
		
		

}); // End doc onReady
