/*
/*	onLoad Functions
/*	----------------
/*	These initialize some of the dynamic functionality used by the theme
*/

jQuery(document).ready(function($) {
		
	// initialise main-menu (jQuery superfish plug-in)
	$('ul.sf-menu').superfish();
	
	// initialize modal (fancybox)
	// -------------------------------------------------------------------
	
	// Quickly setup some special references
	// fancybox doesn't like #name references at the end of links so we find
	// them and modify the link to use a class and remove the #name.
	jQuery('a[href$="#popup"]').addClass('zoom iframe').each( function() {
		jQuery(this).attr('href', this.href.replace('#popup',''));
	});

	// setup fancybox for login modal
	jQuery('a[href$="#login"]').addClass('login').each( function() {
		theHref = jQuery(this).attr('href');
		if (theHref == '#login') {
			theHref = themePath + 'login.html';
		}
		jQuery(this).attr('href', theHref.replace('#login',''))
	});

	// setup fancybox for YouTube
	jQuery("a.zoom[href*='http://www.youtube.com/watch?']").each( function() {
		jQuery(this).addClass('fancyYouTube').removeClass('zoom').removeClass('iframe'); // might have iframe if using #popup
	});

	// setup fancybox for Vimeo
	jQuery("a.zoom[href*='http://www.vimeo.com/'], a.zoom[href*='http://vimeo.com/']").each( function() {
		jQuery(this).addClass('fancyVimeo').removeClass('zoom').removeClass('iframe'); // might have iframe if using #popup
	});
	

	var overlayColor = jQuery('#fancybox-overlay').css('background-color') || '#000';
	
	// fancybox - default
	jQuery('a.zoom').fancybox({
		'padding': 1,
		'overlayOpacity': 0.7,
		'overlayColor': overlayColor,
		'speedIn': 500,
		'speedOut': 500,
		'transitionIn': 'elastic', 
		'transitionOut': 'elastic'
	});
	
	// initialize login modal (fancybox)
	jQuery('a.login').fancybox({
		'padding': 1, 
		'overlayOpacity': 0.7,
		'overlayColor': overlayColor,
		'speedIn': 500,
		'speedOut': 500,
		'showCloseButton': false,
		'transitionIn': 'elastic', 
		'transitionOut': 'elastic',
		'frameWidth': 400,
		'frameHeight': 200,
		'scrolling': 'no',
		'titleShow': false,
		'hideOnContentClick': false		
	});
	
	// fancybox - YouTube
	jQuery('a.fancyYouTube').click(function() {
		jQuery.fancybox({
			'padding': 1,
			'overlayOpacity': 0.7,
			'overlayColor': overlayColor,
			'speedIn': 500,
			'speedOut': 500,
			'transitionIn': 'elastic', 
			'transitionOut': 'elastic',
			'title': this.title,
			'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type': 'swf',
			'swf': {
				'wmode': 'transparent',
				'allowfullscreen'	: 'true'} // <-- flashvars
		});
		return false;
	});

	// fancybox - Vimeo	
	jQuery("a.fancyVimeo").click(function() {
		jQuery.fancybox({
			'padding': 1,
			'overlayOpacity': 0.7,
			'overlayColor': overlayColor,
			'speedIn': 500,
			'speedOut': 500,
			'transitionIn': 'elastic', 
			'transitionOut': 'elastic',
			'title': this.title,
			'href': this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),
			'type': 'swf'
		});
		return false;
	});


	// portfolio item height test (prevents long titles from causing gaps)
	// -------------------------------------------------------------------
	if (jQuery('.gallery-description').length > 0 ) {
		var pi = jQuery('.gallery-description');
		pi.each( function(i, val) {
			if (pi[i].scrollHeight > 115) {
				pi.css('height',pi[i].scrollHeight+'px');
				return false;
			}
		});
	}


	// Text and password input styling
	// -------------------------------------------------------------------
	
	// This should be in the CSS file but IE 6 will ignore it.
	// If you have an input you don't want styles, add the class "noStyle"

	jQuery("input[type='text']:not(.noStyle), input[type='password']:not(.noStyle)").each(function(){
		jQuery(this).addClass('textInput');
	});
	

	// Rounded corner styles
	jQuery('.sf-menu > li a:not(li li a)').css({
		'-moz-border-radius': '3px',
		'-webkit-border-radius': '3px',
		'border-radius': '3px'
	});
	
	// minor style fix for Opera
	if( jQuery.browser.opera ){
		// no margin on button inner <span>
		jQuery('button.btn span').css('margin','0');
	}
	
});

