;(function($) {

	/*
	 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
	 *
	 * Uses the built in easing capabilities added In jQuery 1.1
	 * to offer multiple easing options
	 *
	 * TERMS OF USE - jQuery Easing
	 * 
	 * Open source under the BSD License. 
	 * 
	 * Copyright Â© 2008 George McGinley Smith
	 * All rights reserved.
	 * 
	 * Redistribution and use in source and binary forms, with or without modification, 
	 * are permitted provided that the following conditions are met:
	 * 
	 * Redistributions of source code must retain the above copyright notice, this list of 
	 * conditions and the following disclaimer.
	 * Redistributions in binary form must reproduce the above copyright notice, this list 
	 * of conditions and the following disclaimer in the documentation and/or other materials 
	 * provided with the distribution.
	 * 
	 * Neither the name of the author nor the names of contributors may be used to endorse 
	 * or promote products derived from this software without specific prior written permission.
	 * 
	 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
	 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
	 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
	 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
	 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
	 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
	 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
	 * OF THE POSSIBILITY OF SUCH DAMAGE. 
	 *
	*/

	// t: current time, b: begInnIng value, c: change In value, d: duration
	jQuery.easing['jswing'] = jQuery.easing['swing'];

	jQuery.extend( jQuery.easing,
	{
		def: 'easeOutQuad',
		swing: function (x, t, b, c, d) {
			//alert(jQuery.easing.default);
			return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
		},
		easeInQuad: function (x, t, b, c, d) {
			return c*(t/=d)*t + b;
		},
		easeOutQuad: function (x, t, b, c, d) {
			return -c *(t/=d)*(t-2) + b;
		},
		easeInOutQuad: function (x, t, b, c, d) {
			if ((t/=d/2) < 1) return c/2*t*t + b;
			return -c/2 * ((--t)*(t-2) - 1) + b;
		},
		easeInCubic: function (x, t, b, c, d) {
			return c*(t/=d)*t*t + b;
		},
		easeOutCubic: function (x, t, b, c, d) {
			return c*((t=t/d-1)*t*t + 1) + b;
		},
		easeInOutCubic: function (x, t, b, c, d) {
			if ((t/=d/2) < 1) return c/2*t*t*t + b;
			return c/2*((t-=2)*t*t + 2) + b;
		},
		easeInQuart: function (x, t, b, c, d) {
			return c*(t/=d)*t*t*t + b;
		},
		easeOutQuart: function (x, t, b, c, d) {
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		},
		easeInOutQuart: function (x, t, b, c, d) {
			if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
			return -c/2 * ((t-=2)*t*t*t - 2) + b;
		},
		easeInQuint: function (x, t, b, c, d) {
			return c*(t/=d)*t*t*t*t + b;
		},
		easeOutQuint: function (x, t, b, c, d) {
			return c*((t=t/d-1)*t*t*t*t + 1) + b;
		},
		easeInOutQuint: function (x, t, b, c, d) {
			if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
			return c/2*((t-=2)*t*t*t*t + 2) + b;
		},
		easeInSine: function (x, t, b, c, d) {
			return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
		},
		easeOutSine: function (x, t, b, c, d) {
			return c * Math.sin(t/d * (Math.PI/2)) + b;
		},
		easeInOutSine: function (x, t, b, c, d) {
			return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
		},
		easeInExpo: function (x, t, b, c, d) {
			return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
		},
		easeOutExpo: function (x, t, b, c, d) {
			return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
		},
		easeInOutExpo: 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;
		},
		easeInCirc: function (x, t, b, c, d) {
			return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
		},
		easeOutCirc: function (x, t, b, c, d) {
			return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
		},
		easeInOutCirc: function (x, t, b, c, d) {
			if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
			return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
		},
		easeInElastic: function (x, t, b, c, d) {
			var s=1.70158;var p=0;var a=c;
			if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
			if (a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		},
		easeOutElastic: function (x, t, b, c, d) {
			var s=1.70158;var p=0;var a=c;
			if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
			if (a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
		},
		easeInOutElastic: function (x, t, b, c, d) {
			var s=1.70158;var p=0;var a=c;
			if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
			if (a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
			return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
		},
		easeInBack: function (x, t, b, c, d, s) {
			if (s == undefined) s = 1.70158;
			return c*(t/=d)*t*((s+1)*t - s) + b;
		},
		easeOutBack: function (x, t, b, c, d, s) {
			if (s == undefined) s = 1.70158;
			return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
		},
		easeInOutBack: function (x, t, b, c, d, s) {
			if (s == undefined) s = 1.70158; 
			if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
			return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
		},
		easeInBounce: function (x, t, b, c, d) {
			return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
		},
		easeOutBounce: function (x, t, b, c, d) {
			if ((t/=d) < (1/2.75)) {
				return c*(7.5625*t*t) + b;
			} else if (t < (2/2.75)) {
				return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
			} else if (t < (2.5/2.75)) {
				return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
			} else {
				return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
			}
		},
		easeInOutBounce: function (x, t, b, c, d) {
			if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
			return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
		}
	});

	/*
	 *
	 * TERMS OF USE - EASING EQUATIONS
	 * 
	 * Open source under the BSD License. 
	 * 
	 * Copyright Â© 2001 Robert Penner
	 * All rights reserved.
	 * 
	 * Redistribution and use in source and binary forms, with or without modification, 
	 * are permitted provided that the following conditions are met:
	 * 
	 * Redistributions of source code must retain the above copyright notice, this list of 
	 * conditions and the following disclaimer.
	 * Redistributions in binary form must reproduce the above copyright notice, this list 
	 * of conditions and the following disclaimer in the documentation and/or other materials 
	 * provided with the distribution.
	 * 
	 * Neither the name of the author nor the names of contributors may be used to endorse 
	 * or promote products derived from this software without specific prior written permission.
	 * 
	 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
	 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
	 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
	 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
	 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
	 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
	 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
	 * OF THE POSSIBILITY OF SUCH DAMAGE. 
	 *
	 */

 /*!
	 * slideViewer 1.2
	 * Examples and documentation at: 
	 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/imagestrip/imageslide-plugin.html
	 * 2007-2010 Gian Carlo Mingati
	 * Version: 1.2.3 (9-JULY-2010)
	 * Dual licensed under the MIT and GPL licenses:
	 * http://www.opensource.org/licenses/mit-license.php
	 * http://www.gnu.org/licenses/gpl.html
	 * 
	 * Requires:
	 * jQuery v1.4.1 or later, jquery.easing.1.2
	 * 
	 */

	jQuery(function(){
	   jQuery("div.svw").prepend("<img src='spinner.gif' class='ldrgif' alt='loading...'/ >"); 
	});
	var j = 0;
	var quantofamo = 0;
	jQuery.fn.slideView = function(settings) {
		settings = jQuery.extend({
			easeFunc: "easeInOutExpo",
			easeTime: 750,
			uiBefore: false,
			toolTip: false,
			ttOpacity: 0.9
		}, settings);
		return this.each(function(){
			var container = jQuery(this);
			container.find("img.ldrgif").remove();
			container.removeClass("svw").addClass("stripViewer");		
			var pictWidth = 908;
			var pictHeight = container.find("storefrontContainer").height();
			var pictEls = container.find("li").size();
			var stripViewerWidth = pictWidth*pictEls;
			container.find("ul").css("width" , stripViewerWidth);
			container.css("width" , pictWidth);
			container.css("height" , pictHeight);
			container.each(function(i) {
	    (!settings.uiBefore) ? jQuery(this).after("<div class='stripTransmitter' id='stripTransmitter" + (j) + "'><ul><\/ul><\/div>") : jQuery(this).before("<div class='stripTransmitter' id='stripTransmitter" + (j) + "'><ul><\/ul><\/div>");			
			jQuery(this).find("li").each(function(n) {
			jQuery("div#stripTransmitter" + j + " ul").append("<li><a rel='" + jQuery(this).find("img").attr("rel") + "' href='#'>"+"<\/a><\/li>");												
			});
			jQuery("div#stripTransmitter" + j + " a").each(function(z) {
			jQuery(this).bind("click", function(){		
			jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
			var cnt = -(pictWidth*z);
			container.find("ul").stop().animate({ left: cnt}, settings.easeTime, settings.easeFunc);
			return false;
			});
			});
			
			container.find("span.adminButton ").bind("click", function(e){
				var $container = $(this).parents('.stripViewer:first');
				var ui = (!settings.uiBefore) ? $container.next().find("a.current") : $container.prev().find("a.current");
				var bTotal = parseFloat($container.css('borderLeftWidth').replace("px", "")) +  parseFloat($container.css('borderRightWidth').replace("px", ""));
				var dOs = $container.offset();
				var uinext = ui.parent().next().find("a");
				(jQuery(uinext).length != 0)? uinext.trigger("click") : ui.parent().parent().find("a:first").trigger("click");
			});
			/*cont.find("span.adminButton").click(fucntion() }{
				$containter = $(thsi).prae();
				$container.click();
			})*/
			
			
			jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
			jQuery("div#stripTransmitter" + j + " a:first").addClass("current");
			jQuery('body').append('<div class="tooltip_green" style="display:none;"><\/div>');
			

			if(settings.toolTip){
			var aref = jQuery("div#stripTransmitter" + j + " a");

			aref.live('mousemove', function(e) {
			var att = jQuery(this).attr('rel');
			posX=e.pageX+10;
			posY=e.pageY+10;
			jQuery('.tooltip_green').html(att).css({'position': 'absolute', 'top': posY+'px', 'left': posX+'px', 'display': 'block', 'opacity': settings.ttOpacity});
			});
			aref.live('mouseout', function() {
			jQuery('.tooltip_green').hide();
			});				
			}
			});
			j++;
		});	
	};

})(jQuery);

function getE(name) {
    if (document.getElementById)
        var elem = document.getElementById(name);
    else if (document.all)
        var elem = document.all[name];
    else if (document.layers)
        var elem = document.layers[name];
    return elem;
}

function OpenWindow(query, w, h, scroll) {
    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;

    winprops = 'resizable=1, height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + 'w';
    if (scroll) winprops += ',scrollbars=1';
    var f = window.open(query, "_blank", winprops);
}


jQuery(document).ready(function ($) {
	
	$(".CategoryBreadcrumb a:last").wrap(function() {
	  return '<span>' + $(this).text() + '</span>';
	}).hide();
	
	$('.storefrontButton, .GridImageInner, .ProductImageLink')
	.live("mouseover",function(){
		$(this).addClass('mouseover');
	})
	.live("mouseout",function(){
		$(this).removeClass('mouseover').removeClass('mousedown');
	})
	.live("mousedown",function(){
		$(this).addClass('mousedown');
	})
	.live("mouseup",function(){
		$(this).removeClass('mousedown');
	});
	
	//Photo grid - Fudala fixed this
	function AnimatePhoto(Obj, Val){
		$(Obj).stop().animate({opacity: Val}, {duration: 150});
		$(Obj).dequeue();
	}
	
	$('.ProductImageLink').css({opacity: '0.85'});
	$('.ProductImageLink').mouseenter(function(){
		$(this).queue(function(){AnimatePhoto($(this), '1');});
	}).mouseleave(function(){
		$(this).queue(function(){AnimatePhoto($(this), '0.85');});
	});
	
	//Product showcase page, thumbnail interactions
	$('.ProductThumbContainer .ProductThumbnailInner').eq(0).addClass('selected');
	$('.ProductImageLinkThumb').live("click",function(){
		$('.ProductThumbContainer .ProductThumbnailInner').removeClass('selected');
		$(this).parent().removeClass('selected');
	});
	
	//Form submits, to replace our dodgy buttons...
	$("span.ui-submit-form").click(function () {
		$('input.' + $(this).attr('id')).trigger('click');
	});
	$('.item_replace').click(function(){
		$(this).parent().children('input.'+$(this).attr('rel')).trigger('click');
	});
	
	$('a.ToggleZoom').click(function(){
		if ($(this).hasClass('Enabled'))
		{
			$(this).removeClass('Enabled');
			$('div.mousetrap').hide();
			$('div.productDetailsWrapper').removeClass('ZoomEnabled');
		}
		else{
			$(this).addClass('Enabled');
			$('div.mousetrap').show();
			$('div.productDetailsWrapper').addClass('ZoomEnabled');
		}
	});

	// 
	$('input[type=submit]').click(function () {
		$('div.errorWrapper').each(function (i, item) {
			var $wrapper = $(item);
			var $error = $wrapper.find('span.errorSummary');
			if ($error.size() > 0) {
				var summary = $error.html().trim();
				$wrapper.show();
				var visible = $error.find('div').is(':visible');
				$wrapper.hide();
				if (summary == "" || !visible) {
					$wrapper.hide();
				} else {
					$wrapper.show();
				}
			}
		});
	});

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.aboutTabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$('ul.aboutTabs li').each(function() {
		var $a = $(this).find('a');
		var href = $a.attr('href');
		var title = $a.html();
		$('<span></span>').appendTo($(this)).attr('rel', href).html(title);
		$a.remove();
	});
	$("ul.aboutTabs li").click(function() {
		$("ul.aboutTabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").addClass("tabHidden"); //Hide all tab content

		var activeTab = $(this).find("span").attr("rel"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn().removeClass("tabHidden"); //Fade in the active ID content
		$(".tabHidden").hide();
		return false;
	});

// STOREFRONT TABS

	//When page loads...
	$("ul.storefrontTabs li:first").addClass("active").show(); //Activate first tab
	$(".storefront_tab_content").hide(); //Hide all content
	$(".storefront_tab_content:first").fadeIn(2000); //Show first tab content

	//On Click Event
	$('ul.storefrontTabs li').each(function() {
		var $a = $(this).find('a');
		var href = $a.attr('href');
		var title = $a.html();
		$('<span></span>').appendTo($(this)).attr('rel', href).html(title);
		$a.remove();
	});
	$("ul.storefrontTabs li").click(function() {
		$("ul.storefrontTabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".storefront_tab_content").addClass("tabHidden"); //Hide all tab content

		var activeTab = $(this).find("span").attr("rel"); //Find the href attribute value to identify the active tab + content
		$(activeTab).removeClass("tabHidden").fadeIn(900); //Fade in the active ID content
		$(".tabHidden").hide();
		return false;
	});

// TAKEAWAY WEBSITE STANDARD TABS

	//When page loads...
	$("ul.StandardTabs li:first").addClass("active").show(); //Activate first tab
	$(".StandardTabContainer").hide(); //Hide all content
	$(".StandardTabContainer:first").fadeIn(2000); //Show first tab content

	//On Click Event
	$('ul.StandardTabs li').each(function() {
		var $a = $(this).find('a');
		var href = $a.attr('href');
		var title = $a.html();
		$('<span></span>').appendTo($(this)).attr('rel', href).html(title);
		$a.remove();
	});
	$("ul.StandardTabs li").click(function() {
		$("ul.StandardTabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".StandardTabContainer").addClass("tabHidden"); //Hide all tab content

		var activeTab = $(this).find("span").attr("rel"); //Find the href attribute value to identify the active tab + content
		$(activeTab).removeClass("tabHidden").fadeIn(900); //Fade in the active ID content
		$(".tabHidden").hide();
		return false;
	});

// Product overview tabs

	//When page loads...
	$(".productOverviewInfo").hide(); //Hide all content
	$(".productOverviewInfo#tab1").show();
	$(".productOverviewTakeaway").addClass('hover');

	$("ul.overviewTabs li").hover(function() {
		var thisRel = $(this).find(".productOverviewTab").attr("rel");
		$('.productOverviewTab').removeClass('hover');
		$('.productOverviewInfo').hide();
		$('.productOverviewInfo#'+thisRel).show();
		$(this).find('.productOverviewTab').addClass('hover');
	});

	$(window).bind("load", function() {
		$("div.storefrontFeatureDragDrop").slideView()
	});
	
	
	$('.christmasMain .title h1').empty().html('Planning on updating your site over Christmas?');
	$('.christmasMain .title h2').empty().html('No problem – because Mr Site is ready to help, as always, 24–7 over the Christmas period.<br/><br/>And the New Year period.<br/><br/>And in the middle of the night for all you night-owls out there.<br/>');
	$('.christmasMain .title p').empty().html('So, if you\'re using the break to crack on with your website and want a bit of advice, we’re here - give us a call on 0905 096 0111, drop an email to <a href="mailto:support@mrsite.co.uk">support@mrsite.co.uk</a> or chat online to a guru using our free online Live Chat service.<br/><br/>Thanks for all your support over the last year – we\'ve loved having you as part of the Mr Site community. However you\'re planning on spending the festive season, we wish you the very best and hope that your 2012 is filled with happiness and success.');
	$('.christmasMain .title p').eq(0).show();
	
	$('.christmasWrapper .title').css({visibility: 'visible'});
	
	$('body.productPage').append('<div class="live-help-popout"><div class="live-help-popout-inner"><span class="live-help-popout-top">Not sure which package to go for?<br/><br/>Question about whether building your own website is right for you?</span><span class="live-help-popup-middle">Call us <strong>free</strong> on</span><span class="live-help-popout-number">0800 0124 567</span><span class="live-help-popup-bottom">for jargon-free advice and tips about getting online</span></div></div>');
	
});

window.onload = function() {
	/*$("ul.megamenu li:first").addClass('MrSiteLogoNavigation');
	$("ul.megamenu li:first a span").empty();*/
};
