/**
 * Master Scripts
 * Author: Thom Rimmer, 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);
			input.css('color','#000');
			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'));
				input.css('color','#acacac');
			}
			}).blur().parents('form').submit(function() {
			$(this).find('[placeholder]').each(function() {
				var input = $(this);
				if (input.val() == input.attr('placeholder')) {
					input.val('');
				}
			});
		});
	}
	
	
	/** ---------------------------------------
	 *  Hero-scroll
	 */
	if ( $('.hero-scroll ul').length > 0 ) {
	
		$('.hero-scroll ul').cycle({ 
    		fx:      'fade', 
    		speed:    900, 
    		timeout:  5000 
		});
	}
	
	if ( $('.scroller').length > 0 ) {
	
		$('.scroller').cycle({ 
    		fx:      'fade', 
    		speed:    900, 
    		timeout:  5000 
		});
	}
	
	
	
	$('.view-images').click(function() {
		$('.hero-manual').animate({'height':373});
 		$('.hero-manual .thumbs').slideToggle(200);
 		$(this).fadeToggle(200);
 		return false;
	});
	
	
	$('.minimise').click(function() {
		$('.hero-manual').animate({'height':303});
 		$('.hero-manual .thumbs').slideToggle(200);
 		$('.view-images').fadeToggle(200);
 		return false;
	});
	
	/** ---------------------------------------
	 *  Hero-scroll
	 */
	if ( $('.hero-manual ul').length > 0 ) {
		
		$('.hero-manual ul.cycle').cycle({ 
    		fx:      'fade', 
    		speed:    900, 
    		timeout:  0,
    		pager:   '.thumbs ul',
    		pagerAnchorBuilder: function(i) {
				return '.thumbs ul li a:eq('+i+')';
			}
		});
		
		
	/** ---------------------------------------
	 *  thumbs Carousel
	 */
	 
	 $(".thumbs ul").carouFredSel({
		width: 625,
		align: "left",
		height: 51,
		items: {
			visible: 5,
			width: 125,
			height: 51
		},
		scroll: {
			items: 1,
			duration: 500,
			pauseOnHover: "immediate-resume"
		},
		auto:false,
		prev: ".car-prev",
		next: ".car-next"
	});
		
		
	}
	
	
	/** ---------------------------------------
	 *  content tabs
	 */
	
	if ( $('.content-tabs').length > 0 ) {
		$(".content-tabs ul.tabs").tabs(".content-tabs div.panes > div");
	}
	
	/** ---------------------------------------
	 *  Internal tabs
	 */
	
	if ( $('.internal-tabs').length > 0 ) {
		$(".internal-tabs .tabs ul").tabs(".internal-tabs div.panes > div");
	}
	
	
	/** ---------------------------------------
	 *  siebar height matching
	 */
	if ( $('.posts').length > 0 ) {

			var postheight = ( $('.posts').height() + 5 )
			
			//$('.sidebar').height(postheight);
			$('.sidebar').css("min-height", postheight);
	}
	
	
	
	/** ---------------------------------------
	 *  faq's
	 */
	if ( $('.faq-list').length > 0 ) {
		$('.faq-list li h3').click(function() {
 			$(this).next('div').slideToggle(200);
 			$(this).toggleClass('open');
 			return false;
		});
	}
	
	
	
	
	
})(this.jQuery);
