Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3');
Cufon.replace('h4');


$(document).ready(function(){
		$('#rss, #rssotherproj, #rssmyproj').tipsy({gravity: 'w'});
		$('#tipmail').tipsy({gravity: 's'});
		$('#tiptwitter').tipsy({gravity: 's'});
		$('#submitproj').tipsy({gravity: 'e'});

/*
		var adinfo=["Pay us a coffee and we'll code better","Help us pay our bills", "We need beer money", "A small effort for you, big reward to us"];
		$(".adinfo").each(function () {
			$("<h4>"+  adinfo[Math.floor(Math.random()*adinfo.length)] +"</h4>").appendTo(this);
		});
*/		

		
	    $(".content ul li").click(function () {
	            $(".content ul li").removeClass("active-trail");
	            $(this).addClass("active-trail");
	            //document.title = "The Synapse Project - " + $(this).text();


			//$("#main > #main-inner").hide();
			//$("#main > " + "div." + $(this).find('a').text().toLowerCase()).show();

	    });
	    //paging-slider  and Slider Function
	    rotate = function(){
	        var triggerID = $active.attr("rel") - 1; //Get number of times to slide
	        var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
	    
	        $(".paging-slider a").removeClass('active'); //Remove all active class
	        $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
	    
	        //Slider Animation
	        $(".image_reel").animate({
	            left: -image_reelPosition
	        }, 500 );
	    
	    }; 
	    
	    //Rotation  and Timing Event
	    rotateSwitch = function(){
	        play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
	            $active = $('.paging-slider a.active').next(); //Move to the next paging-slider
	            if ( $active.length === 0) { //If paging-slider reaches the end...
	                $active = $('.paging-slider a:first'); //go back to first
	            }
	            rotate(); //Trigger the paging-slider and slider function
	        }, 7000); //Timer speed in milliseconds (7 seconds)
	    };
	    
	    rotateSwitch(); //Run function on launch
	    
	    //On Hover
	    $(".image_reel a").hover(function() {
	        clearInterval(play); //Stop the rotation
	    }, function() {
	        rotateSwitch(); //Resume rotation timer
	    });	
	    
	    //On Click
	    $(".paging-slider a").click(function() {
	        $active = $(this); //Activate the clicked paging-slider
	        //Reset Timer
	        clearInterval(play); //Stop the rotation
	        rotate(); //Trigger rotation immediately
	        rotateSwitch(); // Resume rotation timer
	        return false; //Prevent browser jump to link anchor
	    });
	    
   
	    
	    //Show the paging-slider and activate its first link
	    $(".paging-slider").show();
	    $(".paging-slider a:first").addClass("active");
	    
	    //Get size of the image, how many images there are, then determin the size of the image reel.
	    var imageWidth = $(".window").width();
	    var imageSum = $(".image_reel img").size();
	    var imageReelWidth = imageWidth * imageSum;
	    
	    //Adjust the image reel to its new size
	    $(".image_reel").css({'width' : imageReelWidth});
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    /*LOGIN  $("div.first").slideUp(300).delay(800).fadeIn(400);	 */
	    $(".btn-slide, #close").click(function(){
	    	$("#panel").slideToggle("normal");
	    });
	    /*$("#loginBtn").click(function(){
	    	$(".loginForm").hide();
	    	$(".loader").show();
	    	$.ajax({
	    	   type: "GET",
	    	   url: "inc/login.php",
	    	   data: "user=" + $(".adminName").val() + "&pass=" + $(".adminPass").val(),
	    	   success: function(msg){
	    			$(".loader").hide();
	    			$(msg).appendTo(".a-content");
	    			wysiwyg();
	    	   }
	    	 });
	    });*/
	    
	    
	    /*NEW MESSAGE*/
	    $("a#submit").click(function(){
	    	$(".views-row").hide();
	    	$(".loader-big").show();
	    	$.ajax({
	    	   type: "GET",
	    	   url: "inc/newmessage.php",
	    	   data: "name=" + $("#name").val() + "&email=" + $("#email").val() + "&company=" + $("#company").val() + "&message=" + $("#question").val(),
	    	   success: function(msg){
	    			$(".loader-big").hide();
	    			$(msg).appendTo("#content-area");
	    	   }
	    	 });
	    });
	    
	    /*NEW PROJECT*/
	    $("a#submitnewproj").click(function(){
	    	$(".newprojsubmit > form#contactform").hide();
	    	$(".newprojsubmit > div.pb50").hide();
	    	$(".loader-big").show();
	    	$.ajax({
	    	   type: "GET",
	    	   url: "inc/newprojreq.php",
	    	   data: "email=" + $("#projmail").val() + "&url=" + $("#url").val() + "&description=" + $("#description").val(),
	    	   success: function(msg){
	    			$(".loader-big").hide();
	    			$(msg).appendTo(".newprojsubmit");
	    	   }
	    	 });
	    });
	    
	    
	    function wysiwyg() {
	    	$("#txtDefaultHtmlArea").htmlarea(); // Initialize jHtmlArea's with all default values
	    	    $("#txtCustomHtmlArea").htmlarea({
                    // Override/Specify the Toolbar buttons to show
                    toolbar: [
                        ["bold", "italic", "underline", "|", "forecolor"],
                        ["p", "h1", "h2", "h3", "h4", "h5", "h6"],
                        ["link", "unlink", "|", "image"]                    
                    ] 
                });
	    }
	    
	    
	    
});
