/** 
 * flashembed 0.31. Adobe Flash embedding script
 * 
 * http://flowplayer.org/tools/flash-embed.html
 *
 * Copyright (c) 2008 Tero Piirainen (tipiirai@gmail.com)
 *
 * Released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * >> Basically you can do anything you want but leave this header as is <<
 *
 * version 0.01 - 03/11/2008 
 * version 0.31 - Tue Jul 22 2008 06:30:34 GMT+0200 (GMT+02:00)
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'([3489b-dfhjlmoqu-wyzA-RT-Z]|1\\w)'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('9 h(j,A,d){9 1a(){8 f="";4(q d==\'9\'){d=d()}4(B.R&&B.1t&&B.1t.1u){f=\'<embed L="1v/x-1w-1b" \';4(3.u){M(3,{C:3.u})}D(8 o E 3){4(3[o]!==v){f+=[o]+\'="\'+3[o]+\'"\\n\\t\'}}4(d){f+=\'d=\\\'\'+1c(d)+\'\\\'\'}f+=\'/>\'}w{f=\'<F classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" \';f+=\'T="\'+3.T+\'" U="\'+3.U+\'"\';4(!3.u&&V.all){3.u="_"+(""+Math.random()).1x(5)}4(3.u){f+=\' u="\'+3.u+\'"\'}f+=\'>\';f+=\'\\n\\t<1d C="movie" 1e="\'+3.N+\'" />\';3.u=3.N=3.T=3.U=v;D(8 k E 3){4(3[k]!==v){f+=\'\\n\\t<1d C="\'+k+\'" 1e="\'+3[k]+\'" />\'}}4(d){f+=\'\\n\\t<1d C="d" 1e=\\\'\'+1c(d)+\'\\\' />\'}f+="</F>";4(O){alert(f)}}b f}9 1y(C){8 1f=setInterval(9(){8 G=V;8 y=G.1g(C);4(y){h(y,A,d);1z(1f)}w 4(G&&G.getElementsByTagName&&G.1g&&G.body){1z(1f)}},13);b 1A}9 M(to,H){4(H){D(o E H){4(H.1h(o)){to[o]=H[o]}}}}8 3={N:\'#\',T:\'1C%\',U:\'1C%\',c:v,W:v,1i:v,O:1D,bgcolor:\'#ffffff\',allowfullscreen:1A,allowscriptaccess:\'1E\',quality:\'high\',L:\'1v/x-1w-1b\',1F:\'http://www.adobe.com/go/getflashplayer\'};4(q A==\'1j\'){A={N:A}}M(3,A);8 c=h.X();8 I=3.c;8 1k=3.1i;8 O=3.O;4(q j==\'1j\'){8 y=V.1g(j);4(y){j=y}w{b 1y(j)}}4(!j){b}4(!I||h.1l(I)){3.W=3.c=3.1i=3.O=v;j.P=1a();b j.firstChild}w 4(3.W){8 Q=3.W.call(3,h.X(),d);4(Q){j.P=Q}}w 4(I&&1k&&h.1l([6,65])){M(3,{N:1k});d={MMredirectURL:location.1G,MMplayerType:\'PlugIn\',MMdoctitle:V.title};j.P=1a()}w{4(j.P.z(/\\s/g,\'\')!==\'\'){}w{j.P="<h2>1m c "+I+" or greater is I</h2><h3>"+(c[0]>0?"Your c is "+c:"You have no 1b plugin installed")+"</h3><p>Download latest c H <a 1G=\'"+3.1F+"\'>here</a></p>"}}9 1c(Y){8 Z="";D(8 o E Y){4(Y[o]){Z+=[o]+\'=\'+11(Y[o])+\'&\'}}b Z.1x(0,Z.1u-1)}9 11(l){switch(1K(l)){12\'1j\':b\'"\'+l.z(14 RegExp(\'(["\\\\\\\\])\',\'g\'),\'\\\\$1\')+\'"\';12\'1L\':b\'[\'+1M(l,9(y){b 11(y)}).1N(\',\')+\']\';12\'9\':b\'"9()"\';12\'F\':8 1n=[];D(8 15 E l){4(l.1h(15)){1n.1O(\'"\'+15+\'":\'+11(l[15]))}}b\'{\'+1n.1N(\',\')+\'}\'}b String(l).z(/\\s/g," ").z(/\\\'/g,"\\"")}9 1K(l){4(l===v||l===1o){b 1D}8 L=q l;b(L==\'F\'&&l.1O)?\'1L\':L}4(1p.1P){1p.1P("onbeforeunload",9(){__flash_unloadHandler=9(){};__flash_savedUnloadHandler=9(){}})}9 1M(16,1Q){8 1q=[];D(8 i E 16){4(16.1h(i)){1q[i]=1Q(16[i])}}b 1q}b j}4(q 1R==\'9\'){(9($){$.fn.M({h:9(3,d){b 1S.each(9(){h(1S,3,d)})}})})(1R)}h=h||{};h.X=9(){8 c=[0,0];4(B.R&&q B.R["1T 1m"]=="F"){8 m=B.R["1T 1m"].description;4(q m!="1o"){m=m.z(/^.*\\s+(\\S+\\s+\\S+$)/,"$1");8 _m=17(m.z(/^(.*)\\..*$/,"$1"),10);8 _r=/r/.test(m)?17(m.z(/^.*r(.*)$/,"$1"),10):0;c=[_m,_r]}}w 4(1p.18){1r{8 J=14 18("K.K.7")}1s(e){1r{J=14 18("K.K.6");c=[6,0];J.AllowScriptAccess="1E"}1s(ee){4(c[0]==6){b}}1r{J=14 18("K.K")}1s(eee){}}4(q J=="F"){m=J.GetVariable("$c");4(q m!="1o"){m=m.z(/^\\S+\\s+(.*)$/,"$1").split(",");c=[17(m[0],10),17(m[2],10)]}}}b c};h.1l=9(c){8 19=h.X();8 Q=(19[0]>c[0])||(19[0]==c[0]&&19[1]>=c[1]);b Q};',[],118,'|||params|if||||var|function||return|version|flashvars||html||flashembed||root||obj|_d||key||typeof||||id|null|else||el|replace|userParams|navigator|name|for|in|object|doc|from|required|_a|ShockwaveFlash|type|extend|src|debug|innerHTML|ret|plugins||width|height|document|onFail|getVersion|vars|out||asString|case||new|prop|arr|parseInt|ActiveXObject|now|getHTML|flash|concatVars|param|value|timer|getElementById|hasOwnProperty|expressInstall|string|express|isSupported|Flash|str|undefined|window|newArr|try|catch|mimeTypes|length|application|shockwave|substring|init|clearInterval|true||100|false|always|pluginspage|href||||typeOf|array|map|join|push|attachEvent|func|jQuery|this|Shockwave'.split('|'),0,{}));

/*
 * Funky Green Machine
 *
 */
 
jQuery(function($) {
 
	var Engine = {
		base_href : 'http://www.funkygreenmachine.com', //change it if you plan to host website in a subfolder
		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);
					}
				});
			},
			addThisButton : function(){
				$('p.addthis-button a').each(function() {
					var btn = $(this);
					btn.mouseover(function() { return addthis_open(this, '', '[URL]','[TITLE]');	});
					btn.mouseout(function() { addthis_close(); });
					btn.click(function() { return addthis_sendto(); });
				});
			}
		},
		enhancements : {
			sidebarNavigation : function(){
				
				//adds expanding functionality to the sidebar
				var hs = $('#wrapper #aside h3').not(':has(a)');
				
				if (hs.length === 0) {
					return;
				}
				
				//add trigger
				hs.wrapInner('<a href="#"></a>');
				
				//hide all elements that are not open
				hs.not('.open').each(function(){
					$(this).nextAll('ul').eq(0).hide();
				});
				
				//change class and hide/show following submenu
				hs.find('a').click(function(e) { 
					e.preventDefault(); 
					var h = $(this).parent().toggleClass('open');
					h.nextAll('ul').eq(0).toggle(); 
				});
			},
			productFilters : function(){
				// Bind the price filter
				var forms = $('#aside form.price-filter');
				forms.find('button').hide();
				forms.find('select').change(function(e){
					$(this).parents('form').trigger('submit');
				});
				

				var forms = $('#aside form.brand-filter');						
				var brands = '<option value="#">Select Brand</option>';
				$('div#brandList ul li a').each(function(){
						brands += '<option value="' + $(this).attr('href') + '">' + $(this).text() + '</option>';
				});
				forms.find('select').html(brands);				
				forms.find('button').hide();
				forms.find('select').change(function(e){
					document.location.href = $(this).attr('value');
				});			
			},
			shoppingCartSummary : function(){				
				var summary = $('.cartSummaryItem').text();
	
				if (summary != 'Shopping cart is empty.'){
					var arr = summary.split(" ");	
					$('#shopping-bag p span#cartItems').text(arr[0] + ' item(s)');
				}			
				else {	
					$('#shopping-bag p span#cartItems').text('0 items');
				}
			},
			getUsernameValidation : function(){
				// validate that the username text box is not blank
				$("#catseczonelpform88882").bind("submit", function(e){
					if ($(this).find('#SZUsername').val() == "") {
						alert('You must provide a valid username or email address before your password can be emailed.');
						return false;
					}				
				});
			},
			featuredProductsRotator : function(){
				
				var timerSpeed = 1; //in seconds
				
			
				//launch on homepage only
				if ($('div.featured-belt').length === 0){
					return;
				}
		
				var level = 0;
				var levels = ($('.featured-products').height()/180)-1;
				var interval = null;
							
				var rotate = function(){
									
					$('.featured-products').hide();
					$('.featured-products').css('margin-top', (-180 * level) + 'px');
					$('.featured-products').fadeIn(2000);

					if (level == levels) { level = 0; }
					else { level++; }

				};				
				
				var resetRotation = function(){
					if (interval !== null) {
						window.clearInterval(interval);
					};
					interval = window.setInterval(rotate, 8000);				
				};					
	
				if (levels > 0) {
					resetRotation();
					rotate();		
				}
			}
		},
		flash : {
			logo : function(){
				// make sure this is only done on the home page
				var path = document.location.href; 
				if (path.split(".com")[1] != "/") { return;} 
								
				//make sure you have a right path to the flash movie if you are rewriting links
				var el = $('#logo').addClass('flash').find('a');
				
				el.parent().append('<span class="offset">'+el.html()+'</span>');
				el.flashembed({
					"src" : Engine.base_href + '/images/logo.swf',
					"height" : 216,
					"width": 360,
					'wmode' : 'transparent'
				});
				el.css('text-indent','0');
			}
		},
		fixes : { 
			png : function(){
				//png transparency
				if (typeof DD_belatedPNG == 'undefined') {
					return;
				}

				$('#external .social img,#shipping-costs, #shopping-bag, #logo').each(function(){
					DD_belatedPNG.fixPng(this);														   
				});
			},
			pagingFix : function(){		
				// For the blog pagination
				if ($('.pagination a').size() === 0){
					$('.pagination').hide();
				}
			},
			activeNav : function(){			
				// Loop through the top navigation
				$('#nav_359362 li a').each(function(){
					var path = document.location.href; 
					var current_href = $(this).attr('href');
										
					if (path.indexOf(current_href) != -1) {
					  $(this).addClass("active");
					}

					if ((current_href == "/login") && ($('#isLoggedIn').text() === "1"))
					{
						$(this).attr('href','/account')	
					}
					
					if ((current_href == "/account") && ($('#isLoggedIn').text() === "0"))
					{
						$(this).attr('href','/login')	
					}
				});
				// Loop through the bottom navigation
				$('#nav_359473 li a').each(function(){
					var path = document.location.href; 
					var current_href = $(this).attr('href');
										
					if ((current_href == "/login") && ($('#isLoggedIn').text() === "1"))
					{
						$(this).attr('href','/account')	
					}
					
					if ((current_href == "/account") && ($('#isLoggedIn').text() === "0"))
					{
						$(this).attr('href','/login')	
					}
				});
				
				// Loop through the bottom navigation			
				$('#aside h3.open').removeClass('open');
				
				$('#aside ul.catalogueitemdump li a').each(function(){
					var path = document.location.href; 
					var current_href = $(this).attr('href');
					
					if (path.indexOf(current_href) != -1) {
					  $(this).addClass("active");
					  $(this).parent().parent().prev("h3").addClass("open");
					}

					$(this).attr('href', Engine.base_href + current_href);
										
				});
				
				// If no nav blocks are open, open up the first nav block
				if ($('#aside h3.open').length === 0){
					$('#aside h3:first').addClass('open');
				}
				
				
			},
			poplets : function(){
				// makes the poplets open up over the main large image instead of the lightbox
								
				$('.productSelectInput').change(function(e){
					Engine.fixes.poplets();
				});
								
				if ($('.productPopletsItem a').size() === 0){ $('#enlarge').hide(); return}
				
				$('.productPopletsItem a').removeAttr('onclick');
				$('.productPopletsItem a').removeAttr('rel');
				
				$('.productPopletsItem a').click(function(e){
					e.preventDefault();
				});
				
				$('.productPopletsItem a').mouseover(function(e){
					$('.photo-viewer .large img').attr("src",$(this).attr('href'));
				});
			},
			brandFix : function(){
				var url = document.location.href; 
				// If the content class is "brand" and the url contains _catalog_ hide the last h1
				
				if (($('.brand').length === 1) && (url.indexOf('_catalog_') != -1)) {
					$('.brand h1:last').remove();
				}				
				
				// If the content class is "brand" and the url contains _product_ hide the first h1
				if (($('.brand').length === 1) && (url.indexOf('_product_') != -1)) {
					$('.brand h1:first').remove();
					$('#brand-detail').remove();
				}
			},
			breadcrumbSeparator : function(){
				if ($('h1.shop').length === 0) { return; }
				
				var txt = $('h1.shop').html().replace(':','>');
				//alert($('h1.shop').text());
				$('h1.shop').html(txt);
			}
		}
	};

	Engine.fixes.png();
	Engine.fixes.pagingFix();
	Engine.fixes.poplets();
	Engine.fixes.brandFix();
	Engine.fixes.activeNav();
	Engine.fixes.breadcrumbSeparator();
	
	Engine.utils.links();
	Engine.utils.mails();
	Engine.utils.addThisButton();		
	
	Engine.enhancements.sidebarNavigation();
	Engine.enhancements.productFilters();
	Engine.enhancements.shoppingCartSummary();
	Engine.enhancements.getUsernameValidation();
	Engine.enhancements.featuredProductsRotator();
	
	Engine.flash.logo();
	
	$('p.ccv a').click(function(e){
		e.preventDefault();
		$('.ccvExplain').css('display','block');
	});
	
	$('span.ccvExplain a').click(function(e){
		e.preventDefault();
		$('.ccvExplain').css('display','none');
	});
	
	$('.productSelectInput').change(function(e){
		Engine.fixes.poplets();
	});
	

});

//add this button
var addthis_pub = "funkygreenmachine";