/**
 * SimpleFlame Content rotator
 * Version 0.2 (28.04.2009)
 * Possible effects to use :
 *  - if UI effects have been added: 'blind', 'bounce', 'clip', 'drop', 'explode', 'fold', 'highlight', 'puff', 'pulsate', 'scale', 'shake', 'size', 'slide', 'transfer'
 *  - basic effects from jQuery: fadeIn, fadeOut, show, hide, slideUp, slideDown
 */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(5(){6 9=5(R,h){2.3={\'d\':\'z\',\'c\':\'M\',\'S\':1e,\'l\':p,\'t\':\'1r\',\'17\':{},\'C\':\'19\',\'m\':\'1k\',\'Q\':{},\'H\':\'19\'};7.1m(2.3,h);2.$g=7(R);2.12()};9.j.12=5(){2.$g.o(\'w-b\');2.$x=7(\'<1l Z="w-1j" />\');2.$g.1n(2.$x);2.$x.I(2.$g);2.$s=7(\'<1o Z="w-s" />\');2.$x.I(2.$s);2.$b=2.$g.1q(2.3.d);2.$e=2.$b.v(2.$b.1p(\'.\'+2.3.c));8(2.$e<0){2.$e=0}6 4=2;2.$b.o(\'w-d\').X(5(v,d){6 q=7(\'<z><a 1s="#">\'+1c(v+1,10)+\'</a></z>\');4.$s.I(q);q.U(\'a\').G(\'d\',d).1h(\'1g\',{4:4},4.q)});2.y(2.$e,p);8(2.3.l){2.l()}};9.j.q=5(D){D.1d();6 4=D.G.4;4.P();4.$O=p;6 k=4.$b.v(7(2).G(\'d\'));4.y(k)};9.j.y=5(k){6 11=1I[1]||14;6 c=2.3.c;6 i=2.$b.L(2.$e);6 f=2.$b.L(k);6 E=5(){i.N(c)};6 A=5(){f.o(c).Y(\'16\',10)};6 J=[\'1H\',\'1G\',\'1K\',\'1N\',\'1M\',\'1t\',\'1L\',\'1J\',\'1E\',\'1F\',\'1w\',\'1v\',\'1u\',\'1y\'];8(11===p){i.N(c).F();f.o(c).B()}n{8(7.1a(2.3.m,J)>-1){i.F(2.3.m,2.3.Q,2.3.H,E)}n 8(7.13(i[2.3.m])){i[2.3.m](2.3.H,E)}n{15"1b F 18"}f.Y(\'16\',1C);8(7.1a(2.3.t,J)>-1){f.B(2.3.t,2.3.17,2.3.C,A)}n 8(7.13(f[2.3.t])){f[2.3.t](2.3.C,A)}n{15"1b B 18"}}2.$s.U(\'a\').N(\'M\').L(k).o(\'M\');2.$e=k};9.j.l=5(){2.$O=14;6 4=2;2.$g.1A(5(){4.P()});2.$g.1B(5(){4.K()});2.K()};9.j.K=5(){8(2.$O===p){V}6 4=2;2.$T=W.1D(5(){6 u=4.$e+1;8(u===4.$b.1z){u=0}4.y(u)},2.3.S)};9.j.P=5(){8(2.3.l){W.1x(2.$T)}};7.1f.9=5(h){h=h||{};V 2.X(5(){6 r=1i 9(2,h)})}})();',62,112,'||this|settings|self|function|var|jQuery|if|sfRotator||items|activeClass|item|current|newItem|container|options|oldItem|prototype|position|autorotate|effectOut|else|addClass|true|trigger||controls|effectIn|next|index|sf|wrapper|activate|li|onShow|show|speedIn|event|onHide|hide|data|speedOut|append|effects|startAutorotate|eq|active|removeClass|rotationTerminated|stopAutorotate|optionsOut|el|duration|rotationInterval|find|return|window|each|css|class||instant|build|isFunction|false|throw|zIndex|optionsIn|transition|normal|inArray|Unsupported|parseInt|preventDefault|5000|fn|click|bind|new|rotator|fadeOut|div|extend|before|ul|filter|children|fadeIn|href|fold|slide|size|shake|clearInterval|transfer|length|mouseenter|mouseleave|100|setInterval|pulsate|scale|bounce|blind|arguments|puff|clip|highlight|explode|drop'.split('|'),0,{}));

/**
 * Compact labels plugin
 */
(function($){$.fn.compactize=function(){return this.each(function(){var label=$(this),input=$('#'+label.attr('for'));input.focus(function(){label.hide();}).blur(function(){if(input.val()===''){label.show();}});window.setTimeout(function(){if(input.val()!==''){label.hide();}},50);});};})(jQuery);

/*
 * hrefID jQuery extention - returns a valid #hash string from link href attribute in Internet Explorer
 */
(function($){$.fn.extend({hrefId:function(){return $(this).attr('href').substr($(this).attr('href').indexOf('#'));}});})(jQuery);

/**
 * sfSlider
 *
 * @version: 1.2
 * @author SimpleFlame http://www.simpleflame.com/
 *
 * Required settings:
 *  display   - provide number of items displayed at once
 *
 * Other settings:
 *  time      - transition time
 *  easing    - easing for the transition
 *  width     - width of the scrolled area (by default visible area + right margin on the last visible item)
 *  previous  - previous link text
 *  next      - next link text
 *  wrap      - wrap container selector
 *  slider    - items container selector
 *  items     - items selector
 *  paging    - set it to true if you want to display paging numbers
 */ 
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(9($){$.13.12=9(P){3 J={8:0,t:6,G:14,F:\'15\',u:\'16\',m:\'11\',k:\'Z.k\',r:\'f.4\',4:\'f.4 j\',5:A};3 2=$.V({},J,P);w v.U(9(){3 h,$b,$g=$(v),$k=$g.c(2.k),$r=$g.c(2.r),$4=$g.c(2.4),L=$4.I(),p=W.X(L/2.t);$4.O(\':M\').q(\'M\');$4.O(\':K\').q(\'K\');l($4.I()<=2.t){w A}3 8=2.8;l(2.8===0){8=$k.8()+T($4.1f(\'1a-19\'),10)}3 7=0;3 $E=$(\'<a y="#u" n="D">\'+2.u+\'</a>\').x(9(e){e.z();h(7-1)});3 $C=$(\'<a y="#m">\'+2.m+\'</a>\').x(9(e){e.z();h(7+1)});3 $s=$(\'<f n="1c"><j n="H"/><j n="m"/></f>\');$s.c(\'.H\').o($E);$s.c(\'.m\').o($C);$g.o($s);l(2.5===S){3 $5=$(\'<f n="5"></f>\');17(3 i=0;i<p;i++){$5.o(\'<j><a y="#">\'+(i+1)+\'</a></j>\')}$b=$5.c(\'a\');$b.N(0).q(\'B\');$b.x(9(e){e.z();h(T($(v).18(),10)-1)});$g.o($5)}h=9(d){l(d===7||d<0||d>=p){w A}7=d;$E.R(\'D\',7===0);$C.R(\'D\',7+1===p);l(2.5===S){$b.1e(\'B\');$b.N(7).q(\'B\')}3 Q=-d*8;$r.1b().Y({\'1d\':Q+\'1g\'},2.G,2.F)}})}})(1h);',62,80,'||settings|var|items|paging||current|width|function||pagingTriggers|find|position||ul|root|move||li|wrap|if|next|class|append|pages|addClass|slider|controls|display|previous|this|return|click|href|preventDefault|false|active|nextTrigger|off|previousTrigger|easing|time|prev|size|defaults|first|all|last|eq|filter|options|offset|toggleClass|true|parseInt|each|extend|Math|ceil|animate|div||Next|sfSlider|fn|500|swing|Previous|for|text|right|margin|stop|index|marginLeft|removeClass|css|px|jQuery'.split('|'),0,{}))


/*
 * Scripts
 *
 */
jQuery(function($) {
 
	var Engine = {
		utils : {
			links : function(){
				$('a[rel*=external]').click(function(e){
					e.preventDefault();
					window.open($(this).attr('href'));						  
				});
			},
			mails : function(){
				$('a[href^=mailto:]').each(function(){
					var mail = $(this).attr('href').replace('mailto:','');
					var replaced = mail.replace('/at/','@');
					$(this).attr('href','mailto:'+replaced);
					if($(this).text() == mail) {
						$(this).text(replaced);
					}
				});
			}
		},
		ui : {
			rotatorInit : function () {
				$('.list-b').sfRotator({
					'duration' : 4000,
					'speedIn': 1200,
					'speedOut': 1200
				});
			},
			sliderInit : function () {	
				$('#content .slider').sfSlider({ display: 4, width: 764, slider : '.wrap ul', items : '.wrap ul li', paging : true });				
			}
		},
		
		tweaks : {
			
			checkoutTotal : function(){
			
			$("#order-summary-value").html("£"+$("#Amount").val());
			
			
			},
			
		checkout : function(){
				// -----------------------------------------------------
				// This will copy over the shipping address value to the 
				// billing address.  Make sure the checkbox Id is "SameAsShipping"
				//
				// * Update - changed to check length and clear fields on unchecked
				// -----------------------------------------------------	
				$("#SameAsShipping").bind("change", function(e){
					
					var n = $("#SameAsShipping:checked").length
						if(n == 0){
							
							$("#BillingAddress").val('');
							$("#BillingCity").val('');
							$("#BillingState").val('');
							$("#BillingZip").val('');
							$("#BillingPhone").val('');
						}else{
							
							
							$("#BillingAddress").val($("#ShippingAddress").val());
							$("#BillingCity").val($("#ShippingCity").val());
							$("#BillingState").val($("#ShippingState").val());
							$("#BillingZip").val($("#ShippingZip").val());
							$("#BillingPhone").val($("#ShippingPhone").val());
						}
				
				});
				
				 if ($('input#Amount').val() === '0.00') {
									$('#PaymentMethodType_9').attr('checked','checked');
									   $('#credit-card-information').css('display','none');    
									   // alert($('input#Amount').val());    
									   }else{
										
										//console.log('nope not zero');
									}
				
				
		},// end checkout
		
		cartBox : function(){
			
				if ($('#catCartSummary .cartSummaryItem').html() != 'Shopping cart is empty.') {
						var summary = $('#catCartSummary .cartSummaryItem').text().split(" ");
						//url = $('.cartSummaryLink').attr('href');
						$(".cartContents").html(summary[0]+ " items");	
					
						
				}else{
					$(".cartContents").html("0 items");	
				}
				
			}, // end cartbox
			
		ecom : function(){
			
			if (document.location.href.indexOf("_product_") != -1){    
						$(".secondary-tb .list-e").hide();
						$(".cols-two-e").css("margin-top","0px");
						$(".box-g, h2.header-f").hide();
						
				   }
				   
			if (document.location.href.indexOf("_catalog_") != -1){    
						$(".slider, h2.header-c").hide();
					}
			   
			if($(".catalogueItemNotFound").html() == "This catalog has no sub-catalogs."){
    			$(".secondary-tb .list-e").hide();
			}
			
			var wishListAction = $(".wishListAction").find("a").attr("href");
			$(".bta-b").attr("href",wishListAction);
			
			var currentUrl = window.location;
			$(".bta-c").attr("href","/tell-a-friend?var="+currentUrl);
			
			$(".bta-a").attr("href",$("#main-image").find("img").attr("src"));
			
			$(".list-h li").find("a:last").css("background","none");
				
			
			
		
		},
		
		loginPeepShow : function(){
			
				$("#btnLostPass").click(function(){
					$("#lostPass").slideToggle();
					return false;
				});
			
				
				$("#btnRegister").click(function(){
					$("#registerForm").slideToggle();
					return false;
				});
			
			
			},
			
		loginCheck : function(){
                    if ($('#isLoggedIn').text() === '1') {
                         $(".box-a .text-d").html("<a href=\"/LogOutProcess.aspx\"><span>Log Out</span></a>");
						 $(".text-d").addClass('log-out');
                    }

		},
		
		favoritesCheck : function(){
		
				if($(".myFavorites").html() === ""){
					$(".myFavorites").html("<em>No Favorites Added Yet</em>");
					
				}
			
		},
		
		favoritesProds : function(){
				$(".smallProd").each(function(){
					var html = $(this).html();
					//console.log(html);
					
					$(this).wrap("<li></li>");
				});
				
				$(".myFavorites").each(function(){
					$(this).find("li").wrap("<ul></ul>");
				});
			},
			
			headerBoxBg : function(){
				$("#top .box-b:nth-child(2)").css("background","url(../images/box-b-bg-right-a.png) 100% 0 no-repeat");

				$("#top .box-b .wrapper-a:not(:first)").css("background","url(../images/box-b-bg-left-a.png) 0 0 no-repeat");


			}


			
		}// end tweaks
	};

	Engine.utils.links();
	Engine.utils.mails();
	Engine.ui.rotatorInit();
	Engine.ui.sliderInit();	
	Engine.tweaks.checkoutTotal();
	Engine.tweaks.checkout();
	Engine.tweaks.cartBox();
	Engine.tweaks.ecom();
	Engine.tweaks.loginPeepShow();
	Engine.tweaks.loginCheck();
	Engine.tweaks.favoritesCheck();
	Engine.tweaks.favoritesProds();
	Engine.tweaks.headerBoxBg();
	
});
