//////////////////////////////////////////////// DOCUMENT READY (INIT) ////////////////////////////////////////////////

$(document).ready(function() {
	// Init cufon
	Cufon.replace('h2')
	Cufon.now();
		
	// Init image zooming
	jQuery('.preview img').zoomImgRollover();
	
	// Init link fading
	$(".link").hover(
		function () {
			$(this).animate({ backgroundColor: "#0E0E0E", color: "#FFFC00;" }, 200);

		}, 
		function () {
			$(this).animate({ backgroundColor: "#FFFFFF", color: "#0E0E0E;"  }, 200);
		}
	);
	
	$("#contact li a").hover(
		function () {
			$(this).animate({ color: "#0E0E0E;" }, 200);

		}, 
		function () {
			$(this).animate({ color: "#FFFFFF;"  }, 200);
		}
	);
	
});

portfolioResize();

//////////////////////////////////////////////// PORTFOLIO RESIZING ////////////////////////////////////////////////

function portfolioResize() {
	var itemWidth = $('#portfolio .item').outerWidth();
	var portfolioWidth = itemWidth * Math.floor(($('#header').outerWidth() - $('#sidebar').outerWidth()) / itemWidth);
	
	if(portfolioWidth < itemWidth) {
		portfolioWidth = itemWidth;
	}
	
	$('#portfolio').css("width",portfolioWidth);
}

$(window).resize(portfolioResize);


//////////////////////////////////////////////// ANCHOR SCROLLING ////////////////////////////////////////////////


$(document).ready(function(){
	$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();

		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 750);
	});
});




//////////////////////////////////////////////// IMAGE ZOOMING ////////////////////////////////////////////////

/*
 * jQuery JavaScript Plugin jquery.zoomImgRollover 0.9.0
 * http://bugsoftware.co.uk/jQuery/
 *
 * Copyright (c) 2010 Ritchie Comley
 * Dual licensed under the MIT and GPL licenses.
 *
 * Date: 2010-01-19 (Thu, 19 January 2010)
 * Revision: 29
 *
 * Dependencies:
 * jQuery 1.4 (jquery.com)
 * 
 */

(function(jQuery){ 

	jQuery.fn.zoomImgRollover = function(options) {

		var defaults = {
			percent:50,
			duration:200
		}; 

		var opts = jQuery.extend(defaults, options);
		
		// static zoom function
		function imageZoomStep(jZoomImage, x, origWidth, origHeight)
		{
			var width = Math.round(origWidth * (.5 + ((x * opts.percent) / 200))) * 2;
			var height = Math.round(origHeight * (.5 + ((x * opts.percent) / 200))) * 2;
				
			var left = (width - origWidth) / 2;
			var top = (height - origHeight) / 2;
		
			jZoomImage.css({width:width, height:height, top:-top, left:-left});
		}

		return this.each(function()
		{
			var jZoomImage = jQuery(this);
			var origWidth = jZoomImage.width();
			var origHeight = jZoomImage.height();
			
			// add css ness. to allow zoom
			jZoomImage.css({position: "relative"});
			jZoomImage.parent().css({overflow: "hidden", display:"block", position: "relative", width: origWidth, height: origHeight});
			
			jZoomImage.mouseover(function()
			{
				jZoomImage.stop().animate({dummy:1},{duration:opts.duration, step:function(x)
				{
					imageZoomStep(jZoomImage, x, origWidth, origHeight)
				}});
			});

			jZoomImage.mouseout(function()
			{
				jZoomImage.stop().animate({dummy:0},{duration:opts.duration, step:function(x)
				{
					imageZoomStep(jZoomImage, x, origWidth, origHeight)
				}});
			});
		});
	};

})(jQuery);
