jQuery(document).ready(function(){	

		/* Header Slideshow */
		/*
		try{
			if(headers.length >1){
				Slideshowheaders = [];
				var n = 0;
				jQuery.each(headers, function() {
					Slideshowheaders.push({'src': this});
				});
				
				jQuery('#header').crossSlide({
					sleep: 3,
					fade: 1
					}, Slideshowheaders);
				}
		}catch(err){}
		*/
		/* Form Validation */
		Validate.form('form.validate');	
		
		
		jQuery('.gallerystack img.thumb').imageScan();

		
			
		/* Tool Tips */
		jQuery('.tip-left').tipsy({fade: true, gravity: 'e'});
		jQuery('.tip-right').tipsy({fade: true, gravity: 'w'});
		jQuery('.tip-top').tipsy({fade: true, gravity: 's'});
		jQuery('.tip-bottom').tipsy({fade: true, gravity: 'n'});
		//DisplayFormValues();
		
		
		
		//DisplayFormValues();
		
		
		/* Image Zoom */
		jQuery('img.zoom').imageZoom({ 
				'size'				:'850',
				'group'				: "content"
			});

		
		
			
		jQuery('#print').click(function(elem){
				print();
			});
			
		jQuery('#mail').attr('href',"mailto:?body="+location.href+"&subject="+document.title);
	
	
	 
	       jQuery('ul.navbar').superfish({ 
	            delay:       1000,                            // one second delay on mouseout 
	            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
	            speed:       'fast',                          // faster animation speed 
	            autoArrows:  false,                           // disable generation of arrow mark-up 
	            dropShadows: true                            // disable drop shadows 
	        }); 
	        
			
		var fbpage = "http://www.facebook.com/raftsonger";
		var tweeter = "raftsonger";
		var blog = "http://www.songerwhitewater.com/raftingblog/";
		
		
		jQuery('#enews').click(function(event){
			 event.preventDefault();
			//console.log("Enews me baby");
			jQuery("#dialog").modal({
					position:['0',],	
					minHeight:200,
					minWidth: 400,
					opacity:65,
					onOpen: function (dialog) {
					dialog.overlay.fadeIn('fast', function () {
						dialog.data.hide();
						dialog.container.slideDown('slow', function () {
							dialog.data.show();
						});
					});
				}
				});

			
		});


		
		jQuery('a.share').each(function(){
                //event.preventDefault();
                
                if (jQuery(this).hasClass("twitter")) {
                    jQuery(this).attr('href',"http://twitter.com/home?status="+location.href).attr("target","_blank");
                    jQuery(this).bind("click", function(e){
                        jQuery.GaTrackEvent('Social Link', 'twitter', window.location, '');
                    });
                }
                if (jQuery(this).hasClass("twitterfollow")) {
                    jQuery(this).attr('href',"http://twitter.com/"+tweeter).attr("target","_blank");
                    jQuery(this).bind("click", function(e){
                        jQuery.GaTrackEvent('Social Link', 'twitter-follow', window.location, '');
                    });
                }
                
                if (jQuery(this).hasClass("facebook")) {
                    jQuery(this).attr('href',"http://www.facebook.com/share.php?u="+location.href).attr("target","_blank");
                    jQuery(this).bind("click", function(e){
                        jQuery.GaTrackEvent('Social Link', 'facebook', window.location, '');
                    });
                } 
                if (jQuery(this).hasClass("facebookfan")) {
                    jQuery(this).attr('href',fbpage).attr("target","_blank");
                    jQuery(this).bind("click", function(e){
                        jQuery.GaTrackEvent('Social Link', 'facebookfan', window.location, '');
                    });
                }
                if (jQuery(this).hasClass("blog")) {
                    jQuery(this).attr('href',blog).attr("target","_blank");
                    jQuery(this).bind("click", function(e){
                        jQuery.GaTrackEvent('Social Link', 'blog', window.location, '');
                    });
                }
                
                if (jQuery(this).hasClass("email")) {
                    jQuery(this).attr('href',"mailto:?body="+location.href+"&subject="+document.title);
                    jQuery(this).bind("click", function(e){
                        jQuery.GaTrackEvent('Social Link', 'email', window.location, '');
                    });
                }
                
        });
		
		
		jQuery('#chatbtn').click(function(e){
				e.preventDefault();
				var sWODomain        = "www.class-vi.com";  
				var sWOChatstart     = "http://chat.onthegorge.com/chat/chatstart.htm";
				sWOChatstart+="?domain="+sWODomain
				window.open(sWOChatstart,'new_win','width=484,height=361');
			});
		
		




    jQuery('#mycarousel').jcarousel({
        auto: false,
        wrap: 'last',
		scroll:3,
        initCallback: mycarousel_initCallback,
		itemFirstInCallback:  function(carousel, item, idx, state) {
   			 //console.log('Item #' + idx + ' is now the first item');
			// console.log(item);
		}
	});



    
});


function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};



function signup(theform){
	var theform = theform;
	console.log(jQuery('#email').val());
	//return false;
	readytosend = "yes";
	//alert("sending");
	
	if(jQuery('#name').val() == ""){
		//highlightRequiered('name', "Required")
		jQuery('#name').val("Name is Required ").addClass("error");
		setTimeout("jQuery('#name').val('')",1500)
		readytosend = "no"
	}else{
		jQuery('#name').removeClass("error");
	}
	if(jQuery('#email').val() =="" || !isValidEmail(jQuery('#email').val())){
		//highlightRequiered('email', "Required")
		tmpemail = jQuery('email').val() || "";
		jQuery('#email').val("Invalid Address").addClass("error");
		setTimeout("jQuery('#email').val(tmpemail)",1500)
		readytosend = "no"
	}else{
		jQuery('#email').removeClass("error");
	}
	
	console.log(readytosend);
	if(readytosend == "yes"){
		var url = '/modules/members/signup.php';
		formcontent = jQuery(theform).html();
		//formid =$(theform).id;
		var pars = jQuery(theform).serialize();
		jQuery.ajax({
		   type: "POST",
		   url: url,
		   data: pars,
		   success: function(msg){
			   jQuery(theform).html(msg);
			   setTimeout("jQuery('#newsbubbleform').html(formcontent)",7000)
			   goal="/goals/newslettersignup.html";
			   try {
					if(pageTracker && formgoal != false){
					   pageTracker._trackPageview(goal); 
				   }
				} catch(err) {}
		   }
		 });
		
		return false;
		//var pars = Form.serialize($(theform))
//		
//			
//			$(theform).update("Loading...");
//			
//			var myAjax = new Ajax.Updater(
//			theform, url, 
//			{
//				method: 'post', 
//				parameters: pars, 
//				evalScripts: true,
//				onSuccess: function(transport) {
//					setTimeout("$(formid).innerHTML = formcontent",10000)
//				  }
//
//			});
		
			
			
	}
}
function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}



var Cookie = {
	set: function(name,value,seconds){
		if(seconds){
			d = new Date();
			d.setTime(d.getTime() + (seconds * 1000));
			expiry = '; expires=' + d.toGMTString();
		}else
			expiry = '';
		document.cookie = name + "=" + value + expiry + "; path=/";
	},
	get: function(name){
		nameEQ = name + "=";
		ca = document.cookie.split(';');
		for(i = 0; i < ca.length; i++){
			c = ca[i];
			while(c.charAt(0) == ' ')
				c = c.substring(1,c.length);
			if(c.indexOf(nameEQ) == 0)
				return c.substring(nameEQ.length,c.length);
		}
		return null
	},
	unset: function(name){
		Cookie.set(name,'',-1);
	}
}


	



function opengallery(id){

	var url = "/modules/Gallery/FlashGallery.php?id="+id;
	var windowheight = document.viewport.getHeight();
	
	 //windowheight = 10;
	// Force popup on IE to avoid JS bug... 
	if (Prototype.Browser.IE){
	 	 windowheight = 10;
	}
  
	if(windowheight < 650){
		window.open(url,"gallery", "height=547,width=752,status=no,toolbar=no,menubar=no,location=no");
	}else{
		this.lightWindow = new lightwindow({hideGalleryTab:true});
		this.lightWindow.activateWindow(
			{href: url, 
			height: 547, 
			width: 752,
			scrolling:false});
	}

}

