/**
 * Master Scripts
 * Author: Motionlab Marketing Ltd.
 * www.motionlab.co.uk
 */

(function($) {
		  
	
		
	/** ---------------------------------------
	 * IE6 PNG fixes
	 */
	
	if(typeof DD_belatedPNG !== 'undefined') {
		DD_belatedPNG.fix('img, .png_bg');
	}
	
	/** ---------------------------------------
	 * Bubbling
	 */
	  
	 $('[data-bubble="to"]').bind('click', function() {
 		var _anchor = $(this).find('[data-bubble="from"]').eq(0);
 		var _location = _anchor.attr('href') || '#';
 		window.location = _location;
 		return false;
 	});
 	
 	$('[data-bubble="from"]').click(function() {
 		/* $(this).closest('[data-bubble="to"]').trigger('click'); */
 		return false;
 	});
	
	/** ---------------------------------------
	 * Custom universal easing
	 */
	
	$.easing.custom = function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	};
	
	$.easing.easeInExpo = function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	};
	
	$.easing.easeOutExpo = function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	};
	
	/** ---------------------------------------
	 * IE6 upgrade message
	 */
	
	if(($.browser.msie && $.browser.version == '6.0')) {
		$('body').prepend("<div style='border: 1px solid #F7941D; background: #FEEFDA; text-align: center; clear: both; height: 75px; position: relative;'><div style='position: absolute; right: 3px; top: 3px; font-family: courier new; font-weight: bold;'><a href='#' onclick='javascript:this.parentNode.parentNode.style.display=\"none\"; return false;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-cornerx.jpg' style='border: none;' alt='Close this notice'/></a></div>    <div style='width: 640px; margin: 0 auto; text-align: left; padding: 0; overflow: hidden; color: black;'>      <div style='width: 75px; float: left;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-warning.jpg' alt='Warning!'/></div>      <div style='width: 275px; float: left; font-family: Arial, sans-serif;'>        <div style='font-size: 14px; font-weight: bold; margin-top: 12px;'>You are using an outdated browser</div>        <div style='font-size: 12px; margin-top: 6px; line-height: 12px;'>For a better experience using this site, please upgrade to a modern web browser.</div>      </div>      <div style='width: 75px; float: left;'><a href='http://www.firefox.com' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-firefox.jpg' style='border: none;' alt='Get Firefox 3.5'/></a></div>      <div style='width: 75px; float: left;'><a href='http://www.browserforthebetter.com/download.html' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-ie8.jpg' style='border: none;' alt='Get Internet Explorer 8'/></a></div>      <div style='width: 73px; float: left;'><a href='http://www.apple.com/safari/download/' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-safari.jpg' style='border: none;' alt='Get Safari 4'/></a></div><div style='float: left;'><a href='http://www.google.com/chrome' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-chrome.jpg' style='border: none;' alt='Get Google Chrome'/></a></div></div></div>");
	}
	
	/** ---------------------------------------
	 * Reverse stacking
	 */

	$('.reverse-stack').each(function() {
		var childLength = $(this).children().length;
		$(this).children().each(function() {	
			$(this).css('zIndex', childLength);
			childLength--;
		});
	});
	
	/** ---------------------------------------
	 * Full height elements
	 */
	
	$('.full-height').each(function() {
		$(this).height($(this).parent().height());
	});
	
	/** ---------------------------------------
	 * Vertically centered elements
	 */
	
	$('.vertical-center').each(function() {
		var mid = $(this).children('.mid').eq(0);
		var val = ((mid.parent().height() - mid.height()) / 2);
		mid.css('top', val + 'px');
	});
	
	/** ---------------------------------------
	 * Horizontal masking (for carousels, tickers, etc.)
	 */
	
	$('.horz-mask').each(function() {
		var self = $(this);
		var height = self.height();
		var width = self.width();
		self.find('.horz-mask-inner > *').css('width', width);
	});
	
	/** ---------------------------------------
	 * Placeholder fallback
	 */
	
	if(!Modernizr.placeholder) {
		$('[placeholder]').focus(function() {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
				input.val('');
				input.removeClass('placeholder');
			}
			}).blur(function() {
			var input = $(this);
			if (input.val() == '' || input.val() == input.attr('placeholder')) {
				input.addClass('placeholder');
				input.val(input.attr('placeholder'));
			}
			}).blur().parents('form').submit(function() {
			$(this).find('[placeholder]').each(function() {
				var input = $(this);
				if (input.val() == input.attr('placeholder')) {
					input.val('');
				}
			});
		});
	}
	
	
	/** ---------------------------------------
	 * Ticker
	 */
	$(function() { 
		$("#scroller").simplyScroll({
			autoMode: 'loop'
		});
	});
	
	
	/** ---------------------------------------
	 * Product Carousel
	 */
	
	/*(function() {
		var cycle = $('.productCara .carousel ul');
		if(cycle.length) {
	
			cycle.before('<div id="nav">').cycle({ 
				fx:      'fade', 
				speed:    1000, 
				timeout:  6000,
				pager:  '#nav'
			});
		}
	})();*/
	
	$(function() {
	$('.productCara .carousel ul').after('<div class="cont"><ul class="gal-nav">').cycle({ 
		fx:     'fade', 
		speed:  1000, 
		timeout: 6000, 
		pager:  '.gal-nav', 
     
		// callback fn to create ul of nav
		pagerAnchorBuilder: function(idx, slide) { 
			return '<li><a href="#">slide link</a></li>'; 
		} 
	});
	});
	
	
	/** ---------------------------------------
	 *  content tabs
	 */
	
	if ( $('ul.tabs').length > 0 ) {
		$("ul.tabs").tabs("div.panes > div", { history: true });
	}
	
	
	/** ---------------------------------------
	 *  launch video overlay
	 */
	if ( $('a.iframe').length > 0 ) {
	$("a.iframe").fancybox({
		'hideOnContentClick': true
	});
	}

	
})(this.jQuery);

