jQuery.noConflict();
jQuery(function($) { 
	
	/* Drop Down Menu (superfish + hoverintent + supersubs)
	___________________________________________________________________ */
	// http://users.tpg.com.au/j_birch/plugins/superfish/#getting-started
	// http://users.tpg.com.au/j_birch/plugins/superfish/#options
	$(".sf-menu").supersubs({ 
			
			minWidth:    12,   // minimum width of sub-menus in em units 
			maxWidth:    47,   // maximum width of sub-menus in em units 
			extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
							   // due to slight rounding differences and font-family 
		}).superfish({			
			dropShadows:    false,
			delay:			400
			
							}); // call supersubs first, then superfish, so that subs are 
                         		// not display:none when measuring. Call before initialising 
                         		// containing tabs for same reason. 



	$('.image-caption').css('opacity','0');
	$('.image-with-caption').hover(
		function () {
			$(this).find('.image-caption').stop().fadeTo(400, .8);
		}, 
		function () {
			$(this).find('.image-caption').stop().fadeTo(200, 0);
		}
	);
	
	
	
	// Tooltips
	$('.tooltip, .flickr_badge_image img').tipsy({gravity: $.fn.tipsy.autoNS, opacity: 1});	
	$('#social a').tipsy({gravity: 'w', opacity: 1, offset: 2});
	$('.image-caption a').tipsy({gravity: 'w', opacity: 1});
	$('a#scroll-top').tipsy({ gravity: 'se' });
	$('a#search-modal').tipsy({ gravity: 'e' });




	
	
	var upperLimit = 100;
	var scrollElem = $('a#scroll-top');
	scrollElem.hide();
	$(window).scroll(function () { 	
		
		var scrollTop = $(document).scrollTop();
		
		if ( scrollTop > upperLimit ) {
			$(scrollElem).stop().fadeTo(300, 1);
		}else{		
			$(scrollElem).stop().fadeTo(300, 0);
		}
	});
	
	
	/* Scroll to top animation
	___________________________________________________________________ */
	$('#scroll-top').click(function(){ 
		$('html, body').animate({scrollTop:0}, 600); return false; 
	});
	
	
	
	
	
	
	
	
	
	/* Lightbox (Fancybox)
	___________________________________________________________________ */
	// Ex: open any link <a href="large.jpg" />...
	$('a[href$="jpg"], a[href$="jpeg"], a[href$="png"], a[href$="gif"]').fancybox();

	// Vimeo Popup - Regula Size
	$(".vimeo-popup").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),
			'type'			: 'swf'
		});
		return false;
	});
	
	// Youtube Popup
	$(".youtube-popup").click(function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'			: 640,
				'height'		: 360,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
				   	 'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});
	
		return false;
	});

	// Default Modal box
	$(".modal-box").fancybox({
		'modal' : true
	});
	
	// iFrame
	$(".iframe").fancybox({
		'width' : '95%',
	    'height' : '95%',
	    'autoScale' : false,
	    'transitionIn' : 'none',
	    'transitionOut' : 'none',
	    'type' : 'iframe'
	}); 
	
	$("#search-modal").fancybox({
		'modal' : true,
		'width' : 500,
		'height' : 50
	});
	
	
	
	/* Contact Form Validation
	___________________________________________________________________ */
	var hasChecked = false;
	$(".standard #cf_submit").click(function () { 
		hasChecked = true;
		return checkForm();
	});
	$(".standard #cf_name,.standard #cf_email,.standard #cf_message").live('change click', function(){
		if(hasChecked == true) {
			return checkForm();
		}
	});
	function checkForm() {
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		if($(".standard #cf_name").val() == '') {
			$("#cf_name").addClass('error');
			hasError = true;
		}else{
			$("#cf_name").removeClass('error');
		}
		if($("#cf_email").val() == '') {
			$("#cf_email").addClass('error');
			hasError = true;
		}else if(!emailReg.test( $("#cf_email").val() )) {
			$("#cf_email").addClass('error');
			hasError = true;
		}else{
			$("#cf_email").removeClass('error');
		}
		if($("#cf_message").val() == '') {
			$("#cf_message").addClass('error');
			hasError = true;
		}else{
			$("#cf_message").removeClass('error');
		}
		if(hasError == true){
			return false;
		}else{
			return true;
		}
	}
	// end contact form validation	
	
	
	

}); // end jQuery


