$(document).ready(function() {

	/* Cufon.replace('h3', {hover: true});	 */


	/* login labels */

	$("#login input").ezpz_hint();

		
	/* Client Login */
	
	$("#login_btn a").click(function () { 
		jQuery.easing.def = "easeInOutCubic";
		$("#login").fadeIn(400);
		$("#login_btn a").hide();
  	});

	$("#cancel a").click(function () { 
		jQuery.easing.def = "easeInOutCubic";
		$("#login").fadeOut(400);
		$("#login_btn a").fadeIn(400);
  	});
		

	/* Small Screen Fix */

	navposition = function() {
		if( $(window).height() < 600 || $(window).width() < 900 ) {
			$("#sidebar").css("position", "absolute");
		} else {
			if( $.browser.msie ) {
				// IF IE
				if( $.browser.version.substr(0,1) == "6") {
					// IF IE 6
					$("#sidebar").css("position", "absolute"); }
				else {
					// IF OTHER THAN IE 6
					$("#sidebar").css("position", "fixed");
				}
			} else {
				// IF NOT IE
				$("#sidebar").css("position", "fixed");
			}
		}				
	}
				
	$(window).resize( function() {
		navposition();
	});

	navposition();


	/* Contact Form */
	
	var options = { target:'#alert' };
	$('#contact_form').ajaxForm(options);	
	
	$.fn.clearForm = function() {
	  return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
		  return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
		  this.value = '';
		else if (type == 'checkbox' || type == 'radio')
		  this.checked = false;
		else if (tag == 'select')
		  this.selectedIndex = -1;
	  });
	};

	
	/* FancyBox */
	
	$("a#example1").fancybox();

			$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			
			$("a[rel=example_group2]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
	
	
			$("a[rel=example_group3]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			
			
			$("#various3").fancybox({
				'width'				: '95%',
				'height'			: '95%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$("#various4").fancybox({
				'width'				: '95%',
				'height'			: '95%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$("#various5").fancybox({
				'width'				: '95%',
				'height'			: '95%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$("#various6").fancybox({
				'width'				: '95%',
				'height'			: '95%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$("#various7").fancybox({
				'width'				: '95%',
				'height'			: '95%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});

	
	/* Page Scroll */
	
	function filterPath(string) {
	return string
		.replace(/^\//,'')
		.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
		.replace(/\/$/,'');
	}
	
	var locationPath = filterPath(location.pathname);
	
	// for every navigation link
	$('a[href*=#nav]').each(function() {
		var thisPath = filterPath(this.pathname) || locationPath;
		if (  locationPath == thisPath
		      && (location.hostname == this.hostname || !this.hostname)
		      && this.hash.replace(/#/,'') ) {
		    // grab the target element
			var $target = $("#wrapper " + this.hash);
			var target = this.hash;
			
			// if the target actually exists
			if (target) {
			
				var targetOffset = $target.offset().top;
				
				// assign the scroll event to the navigation link
				$(this).click(function(event) {
					event.preventDefault();
					$('#wrapper').animate({scrollTop: targetOffset}, 600, 'easeInOutCubic', function() {
						
						location.hash = target;
					});
				});
			}
		}
	});
});



