var roguewave = {  
	'goSection': function(e,currentSection){ 
		// if ( window.console ) {console.log("goSection("+currentSection+")");}      
            
		if(currentSection == "shop"){
			return;
		}         
		var theSelectedNavItem = "#nav-"+currentSection;
		var theSelectedSection = "#section-"+currentSection; 
		var theSelectedH1Header = "#h1-"+currentSection;

		// section-specific behaviors
		if (currentSection != "store" ) { 
			switch(currentSection) {
				case "home":
					if (cachedhome == null) {
						// console.log("fetching to fill cache");
						$.get(currentSection+'/', function(data) {
							$('#middle-scroller').empty();
							$('#middle-scroller').html(data);      
							cachedhome = data;
							if (resetDelayTimer == null) {                                           
							}	
							else {                                      
								window.clearTimeout(resetDelayTimer);             
							}        
							roguewave.setupAccordion(e);       
							resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",50);
						});         

					}                                     
					else {
				  		// console.log("using cached content");
						$('#middle-scroller').empty();
						$('#middle-scroller').html(cachedhome);      
					}                           
					break;
				case "music":
					if (cachedmusic == null) {
						// console.log("fetching to fill cache");
						$.get(currentSection+'/', function(data) {
							$('#middle-scroller').empty();
							$('#middle-scroller').html(data);      
							cachedmusic = data;
							if (resetDelayTimer == null) {                                           
							}	
							else {                                      
								window.clearTimeout(resetDelayTimer);             
							}        
							roguewave.setupAccordion(e);       
							resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",50);
						});         

					}                                     
					else {
				  		// console.log("using cached content");
						$('#middle-scroller').empty();
						$('#middle-scroller').html(cachedmusic);      
					}                           
					break;
				case "tour":
					if (cachedtour == null) {
						// console.log("fetching to fill cache");
						$.get(currentSection+'/', function(data) {
							$('#middle-scroller').empty();
							$('#middle-scroller').html(data);      
							cachedtour = data;
							if (resetDelayTimer == null) {                                           
							}	
							else {                                      
								window.clearTimeout(resetDelayTimer);             
							}        
							roguewave.setupAccordion(e);       
							resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",50);
						});         

					}                                     
					else {
				  		// console.log("using cached content");
						$('#middle-scroller').empty();
						$('#middle-scroller').html(cachedtour);      
					}                           
					break;
				case "gallery":
					if (cachedgallery == null) {
						// console.log("fetching to fill cache");
						$.get(currentSection+'/', function(data) {
							$('#middle-scroller').empty();
							$('#middle-scroller').html(data);      
							cachedgallery = data;
							if (resetDelayTimer == null) {                                           
							}	
							else {                                      
								window.clearTimeout(resetDelayTimer);             
							}        
							roguewave.setupAccordion(e);       
							resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",50);
						});         

					}                                     
					else {
				  		// console.log("using cached content");
						$('#middle-scroller').empty();
						$('#middle-scroller').html(cachedgallery);      
					}                           
					break;
				case "blog":
					if (cachedblog == null) {
						// console.log("fetching to fill cache");
						$.get(currentSection+'/', function(data) {
							$('#middle-scroller').empty();
							$('#middle-scroller').html(data);      
							cachedblog = data;
							if (resetDelayTimer == null) {                                           
							}	
							else {                                      
								window.clearTimeout(resetDelayTimer);             
							}        
							roguewave.setupAccordion(e);       
							resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",50);
						});         

					}                                     
					else {
				  		// console.log("using cached content");
						$('#middle-scroller').empty();
						$('#middle-scroller').html(cachedblog);      
					}                           
					break;

				default:
					break;
		    }

			// $.get(currentSection+'/', function(data) {
			// 	$('#middle-scroller').empty();
			// 	$('#middle-scroller').html(data);      
			// });         

			if (resetDelayTimer == null) {                                           
			}	
			else {                                      
				window.clearTimeout(resetDelayTimer);             
			}        
			roguewave.setupAccordion(e);       
			resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",50);

		}
		// else {                                                      
		// 	$('#middle-scroller').empty();      
		// 	$("#nav li a").each(                                                       
		// 		function(intIndex){
		// 			var nameRoot = this.id.substring(4);    
		// 			if (nameRoot != "home" && nameRoot != "store") {
		// 				$.get(nameRoot+'/', function(data) {   
		// 					$('#middle-scroller').append(data);
		// 					if (resetDelayTimer == null) {
		// 						resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",400);
		// 					}  
		// 					else {                                      
		// 						window.clearTimeout(resetDelayTimer);             
		// 						resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",400);
		// 					}
		// 				}); 
		// 				if (resetDelayTimer == null) {
		// 					resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",400);
		// 				}  
		// 				else {                                      
		// 					window.clearTimeout(resetDelayTimer);             
		// 					resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",400);
		// 				}
		// 			}
		// 		}
		// 	);         
		// 	setTimeout("roguewave.homepageAccordion()",300);
		// }       	
		$("#nav li a").each(                                                    
			function(intIndex){
				// Remove .active from all nav items
				$(this).removeClass('active');    
				        
				// Turn on this section of content 
				var nameRoot = this.id.substring(4);
				var sectionName = "#section-"+nameRoot;
				$(sectionName).show();

				// Turn off all section headers
				var sectionH1Header = "#h1-"+nameRoot;
				$(sectionH1Header).hide();
			}       
		);
		// Add .selected to current nav item
		$(theSelectedNavItem).addClass('active'); 

		// Turn on this content section and header 
		$(theSelectedSection).show();             
		$(theSelectedH1Header).show();  

		roguewave.setupAccordion(e);       
		if (resetDelayTimer == null) {
			resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",100);
		}
	},  
	'doFilter': function(e,currentFilter) {     
		// if (window.console) {console.log("doFilter("+currentFilter+")");}
		if (currentFilter == "images") {currentFilter = "Image";}
		if (currentFilter == "exclusives") {currentFilter = "Exclusive";}
		if (currentFilter == "features") {currentFilter = "Feature";}
		if (currentFilter != "all") {  
			// console.log("not ALL");  
			$(".item").hide();
			$(".item-"+currentFilter).show(); 
			$(".item").removeClass('expanded');        
			$(".item").find(".body").slideUp(50,function() {
				roguewave.resetScrolling()
			});
			$(".item-"+currentFilter+":eq(0)").addClass('expanded'); 
			$(".item-"+currentFilter+":eq(0)").find(".body").slideDown(200,function() {
				roguewave.resetScrolling()
			});
		} else {                       
			// console.log("ALL");
			$(".item").show();  
			$(".item").removeClass('expanded');        
			$(".item").find(".body").slideUp(50,function() {
				roguewave.resetScrolling()
			});
			
			$(".item:eq(0)").addClass('expanded');
			$(".item:eq(0)").find(".body").slideDown(200,function() {
				roguewave.resetScrolling()
			});
			
		} 
		// reset Scrolling 
		if (resetDelayTimer == null) {
			resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",200);
		} else {                                      
			window.clearTimeout(resetDelayTimer);             
			resetDelayTimer = window.setTimeout("roguewave.resetScrolling()",200);
		}  
	},	
	'setupAccordion': function(e){                             
		// if ( window.console ) {console.log("setupAccordion()");} 
		$("#middle-scroller .item .body").hide(); 
		// turn on the first item                                  
		$("#middle-scroller .item:eq(0) .body").show();             
		$("#middle-scroller .item").removeClass('expanded');        
		$("#middle-scroller .item:eq(0)").addClass('expanded');
		$("#middle-scroller .item .head").toggle(function(e) { 
		  	$(e.currentTarget.parentNode).addClass('expanded'); 
		  	$(e.currentTarget.parentNode).find(".body").slideDown(200,function() {
				roguewave.resetScrolling()
			});  
		}, function(e) {
		  	$(e.currentTarget.parentNode).removeClass('expanded');
		  	$(e.currentTarget.parentNode).find(".body").slideUp(200,function() {
				roguewave.resetScrolling()
			});      
		});                                                                         
	}, 
	'homepageAccordion': function() {
		$("#middle-scroller .item:eq(0) .body").show();             
		$("#middle-scroller .item").removeClass('expanded');        
		$("#middle-scroller .item:eq(0)").addClass('expanded');
	},  
	'positionFooter': function() {        
		// if ( window.console ) {console.log("positionFooter()");}

		// get dimensions           
		viewportHeight = $(window).height();
		playerHeight = $("#playerbar").height();
		viewportScrollTop = $(window).scrollTop();

		// calculate placement
		vertPlacementFixed = (viewportHeight - playerHeight)+"px";  
		vertPlacementScrolling = (viewportHeight - playerHeight + viewportScrollTop)+"px";     
           
	  	// set placements per position type
		if (!$.browser.msie) {      	
			$("#playerbar").css('position', 'fixed');  
			$("#playerbar").css('top', vertPlacementFixed);      
			$("#playerbar").fadeIn();
		}
		if ($.browser.msie) {
			$("#playerbar").css('position', 'absolute');
			$("#playerbar").css('top', vertPlacementScrolling);      
		}                   
	},
  	'monitorScrolling': function() { 
		if ($.browser.msie) {      
			$(window).scroll(function () {                                              
				roguewave.positionFooter();
			});
		}
	},
	'resetScrolling': function(){  
		// if ( window.console ) {console.log("resetScrolling()");}   	    
		theRemainder = (($(window).height() - $('#h1header').height() - $("#promo2").height() - $("#playerbar").height())+"px");   
		$("#middle-matting").css('height',theRemainder);   	 
		if ($(".jScrollPaneContainer").length) {                                                            
			$(".jScrollPaneContainer").css('height',theRemainder);   	                                     
		}                                                                                                    
		$("#middle-scroller").jScrollPane({scrollbarWidth: 20, maintainPosition: true});           
	},
	'signupFancybox': function() {   
		$("#signup-button").fancybox({
		   	'hideOnContentClick'	: false,
			'content'				: signupformcontent,  
			'titleShow'				: false,
			'onComplete'			: roguewave.setupForm,
			'transitionOut'			: 'fade', 
			'speedOut'				: '750'
		});                                

	},
	'setupForm': function() {
		$("#email").bind("focus",function(){
			if ($(this).attr("value") == "Email") {$(this).attr({value: ""});}
		});
		$("#email").bind("blur",function(){
			if ($(this).attr("value") == "") {$(this).attr({value: "Email"});}
		});                                                              
		$("#fname").bind("focus",function(){
			if ($(this).attr("value") == "First Name") {$(this).attr({value: ""});}
		});
		$("#fname").bind("blur",function(){
			if ($(this).attr("value") == "") {$(this).attr({value: "First Name"});}
		});                                                              
		$("#lname").bind("focus",function(){
			if ($(this).attr("value") == "Last Name") {$(this).attr({value: ""});}
		});
		$("#lname").bind("blur",function(){
			if ($(this).attr("value") == "") {$(this).attr({value: "Last Name"});}
		});                                                              
		$("#city").bind("focus",function(){
			if ($(this).attr("value") == "City") {$(this).attr({value: ""});}
		});
		$("#city").bind("blur",function(){
			if ($(this).attr("value") == "") {$(this).attr({value: "City"});}
		});                                                              
		$("#zip").bind("focus",function(){
			if ($(this).attr("value") == "Zip") {$(this).attr({value: ""});}
		});
		$("#zip").bind("blur",function(){
			if ($(this).attr("value") == "") {$(this).attr({value: "Zip"});}
		});                                                              
		$("#country").bind("change",function(){
			if ($("#country").attr("selectedIndex") !== 0) {
				$("#zip").hide();
			}
			else {
				$("#zip").show();
			}
		});
		$("#mysubmit").bind("click", function() { 

			jQuery.ajax({
                type: "POST",
                url: "/mlist/",
                // dataType:"html",
                data:$("#signup form").serialize(),
                success:function(response){       
					if (response == "ok") { 
						$("#signup .hd h2").html("Success!");  
						$.fancybox.close();
						$("#playerbar .right .default p").hide();  
						$("#signup-button").hide();  
						$("#signup").hide();
						$("#thanks").fadeIn('slow');   
					} 
					else {
		        		$("#signup .hd h2").html("Sorry, there's been an error!"); 
		        		$("#signup .bd .left").html("<h3 style='color:red;margin-bottom:1em;'>Please correct the following errors:</h3>"+response);
					}
					return false;
                },
                error:function(response){  
	        		$("#signup .hd h2").html("Sorry, there's been an error!"); 
	        		$("#signup .bd .left").html("<p>Please try again!</p>"+response);
                }    
            });
            
			
			
			
			// $.post("/mlist", $("#signup form").serialize());  
			// $.fancybox.close();
			// $("#playerbar .right .default p").hide();  
			// $("#signup-button").hide();  
			// // $("#playerbar .right .default a").css("visibility","hidden");  
			// $("#signup").fadeOut();
			// $("#thanks").fadeIn();  
			return false;
		});
	}
};