
function Portfolio(){

	var sPortfolio = "#projects";
	var oPortfolio;
	var oSelected;
	
	var self = this;
	
	this.init =function(){
	
		oPortfolio = $(sPortfolio);
		setSelected('#menu-projects-menu li:first');
		setActions();
		
		$('#menu-projects-menu li h3').each(function() {
			//console.log($(this).height());
			if($(this).height() > 60){
				$(this).parent().addClass("multi");
			}
			else if($(this).height() < 30){
				$(this).parent().addClass("sing");
			}
		});
		
		if ( $.browser.msie ) {
		  if(parseInt($.browser.version, 10) <= 8){
		  	$('#menu-projects-menu li.selected a').hover();
		  	$('#menu-projects-menu li a').hover(function(){
		  		
		  		if(!$(this).parent().hasClass('selected'))
		  			$(this).find('img').fadeOut();
		  		
		  		},function(){
		  		if(!$(this).parent().hasClass('selected'))
		  			$(this).find('img').fadeIn();
		  		
		  		}
		  	);
		  	
		  }
		}
		
	}
	
	this.init();
	
	function setSelected(item){
		
		$(item).addClass('selected');
		$(oSelected).removeClass('selected');
   		oSelected = $(item);
   		
   		oldHeight = $('#projects-box .project').height();
   		$('#projects-box .project-images').cycle('destroy');
   		
   		
   		$('#projects-box .project').remove();
   		

   		$(item).find('.project').clone().appendTo('#projects-box');
   		
   		newHeight = $('#projects-box .project').height();
   		
   		theDifference = Math.abs(oldHeight - newHeight);
   		
   		//alert("Old Height: "+oldHeight+", New Height: "+newHeight+". The Difference is "+theDifference);
   		
   		if(oldHeight < newHeight)
   			theHeight = oldHeight + theDifference;
   		else
   			theHeight = oldHeight - theDifference;
   		
   		
   		
   		$('#projects-box').animate(
		 { height: theHeight }, {
		     duration: 'slow'
		 });

		
		$('#projects-box .project-images').cycle({
			fx:     'fade',
		    speed:  'slow',
		    next:   '#next', 
			prev:   '#prev',
		    timeout: 7000
	
		});
	}
	
	function setActions(){
		$('#menu-projects-menu li a').click(function (e) { 
			e.preventDefault();
			setSelected($(this).parent());
		});
	}
	
}


$(document).ready(function() {
	

	if($('.images img').length >1){	
	
    	$('.images').cycle({
			fx:     'fade',
		    speed:  'slow',
		    next:   '#next', 
			prev:   '#prev',
		    timeout: 7000
	
		});
		
	}
	
	if ($('#contactForm').exists()){ 
		var oContactForm = new contactForm();
   	}
   	
   	if($('.project').exists()){
   		var oPortfolio = new Portfolio();
   	}
		
});

$.fn.exists = function(){return $(this).length>0}
