$(document).ready(function(){
	//Index page Featured Graphics Slider
	if ($('#mainGraphic').length) {
		$('#mainGraphic').coinslider({
			width: 380, // width of slider panel
			height: 250, // height of slider panel
			spw: 1, // squares per width
			sph: 1, // squares per height
			delay: 6000, // delay between images in ms
			sDelay: 30, // delay beetwen squares in ms
			opacity: 0.8, // opacity of title and navigation
				titleSpeed: 500, // speed of title appereance in ms
				effect: 'straight', // random, swirl, rain, straight
				navigation: true, // prev next and buttons
				links : true, // show images as links 
				hoverPause: true // pause on hover
			});
		}
		//Main Navigation
		$('#navigation > ul > li').hover(function(){
			$(this).addClass('navHover');
			$(this).children('a').children('.navDescription').fadeIn(500);
		},function(){
			$(this).removeClass('navHover');
			$(this).children('a').children('.navDescription').hide();
		});
		
		//Main Navigation, makes nav subtext visable.
		$('#navigation > ul > li.currentPage').children('a').children('.navDescription').addClass('activeDescription').removeClass('navDescription');
		
			
		//if jQuery loads then remove all href attributes from the portfolio navigation
		$('#portfolioNav > a').each(function(index){
			$(this).removeAttr('href');
			$(this).css('cursor','pointer');
		});
		
		//Click event for portfolio navigation
		$('#portfolioNav > a').live('click', function(){	
			$('.activePortfolioNav').removeClass('activePortfolioNav');
			$(this).addClass('activePortfolioNav');
			var filter = $(this).html();
			switch(filter){
				case "All":
					$('.pItem').each(function(index){
						$(this).fadeIn(500);
					});
					break;
				case "A long time ago":
					window.location = 'http://www.navaroli.com/oldNavaroli';
					break;
				default:
					$('.pItem').each(function(index){
						var iC = $(this).attr('class')
						if(( iC == "pItem "+filter) || (iC == filter+" pItem")){
							$(this).fadeIn(500);
						} else {
							$(this).fadeOut(500);
						}
					});
			}
		});
		
		//Portfolio Click events only for javascript
		$('.pItem').each(function(index){
			//Remove href for non-javascript enabled browsers.
			$(this).children('.pTitle').children('a').removeAttr('href');
			//Add Click Event
			$(this).click(function(){
				$.colorbox({
				href:"portfolioModal.php?item="+$(this).children('.pTitle').children('a').html(),
				width: "763px",
				height: "500px",
				iframe: "true"
				});
			});
		});
		
		//Portfolio Item Hovers
		$('.pItem').hover(function(){
			$(this).addClass('pItemActive').removeClass('pItem');		
		},function(){
			$(this).addClass('pItem').removeClass('pItemActive');
		})	
		
		//Contact Form
		if($('#contactForm').length){
			$('#contactAgain').live('click',function(){
				$('#contactForm').fadeIn(200);
				$('#contactThankYou').fadeOut(200);
			});
			$('#contactForm').removeAttr('action');
			$('#contactForm').removeAttr('method');
			$('#contactSubmit').remove();
			$('#contactForm').append("<div id='contactSubmit'>submit</div>");
			$('#contactSubmit').live('click',function(){
				var formData = $('#contactForm').serialize();
				formData += "&ajax=TRUE";
				$.ajax({
					type: "POST",
					data: formData,
					url: "./scripts/theElectronicoMailForm.php",
					success: function(response){
						if(response == "1"){
							$('#contactForm').fadeOut(200);
							$('#contactThankYou').fadeIn(200);
						}else if(response == "0"){
							alert("There was an error in processing, please submit again");
						}
					}
			});
		});
	}
	
	var getPortfolio = getUrlVars();
	if(getPortfolio['item']){
		$('.pTitle').each(function(index){
			if($(this).children('a').html() == unescape(getPortfolio['item'])){
				$(this).parents().click();
			}
		});
	}	
		
	function getUrlVars(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++){
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
		}
		return vars;
	}
});



	/* Trying to make the google images effect
	var position;
	var width;
	var offset;
	$('.pItem').hover(function(){
		//position = $(this).position();
		offset = $(this).offset();
		width = $(this).width();
		$(this).css('width',width+20+'px');
		$(this).css('position','fixed');
		$(this).css('z-index','20');
		$(this).css('top',offset.left);
		$(this).css('left',offset.top);
	},function(){
		$(this).css('width',width+	'px');
		$(this).css('position','relative');
		$(this).css('z-index','10');
		//$(this).css('top',offset.left);
		//$(this).css('left',offset.top);
	});
	*/
