

jQuery(document).ready(function($) {
    Cufon.replace('h1');
    Cufon.replace('h2');
    Cufon.replace('h3');
    Cufon.replace('h4');
    $('#term').hint();

	var windowURL = window.location;  //this checks the URL to see if we are home or not. If not at home page, then it doesn't start the animation cycle
	
	//alert(windowURL);
	
	if (windowURL == "http://www.srps.com/" || windowURL == "http://srps.com/" || windowURL == "http://www.solarrenewablepowersystems.com.php5-8.dfw1-1.websitetestlink.com/" || windowURL == "http://www.solarrenewablepowersystems.com/" || windowURL == "http://solarrenewablepowersystems.com/" ) {	
		setTimeout('changeImage()',9000);
    }

});

//submits sidebar contact form via AJAX
// !Move to its own JavaScript file
$(function(){
	$("#submitbutton").click(function() 
	{
	
		if ($(this).attr('value') == 'Message Sent Successfully!') 
		{
			// !Change to !=Submit 
			alert('Cannot resubmit form.\nRefresh page and try again.');
			return false;
		}
		
		if ($("input#date").val() != '') //checks for robots with hid field
		{
			return false;
		}
		
		var name = $("input#name").val();
		if (name == "") 
		{
			//label turns RED if emtpy
			$("label#lblName").css('color','red');
			$("input#name").focus();
			return false;		
		}
		
		var email = $("input#email").val();
		if (email == "") 
		{
			//label turns RED if empty
			$("input#email").focus();
			$("label#lblEmail").css('color','red');
			return false;
		}
		
		var message = $("textarea#message").val();
		if (message == "") 
		{
			//label turns RED if empty
			$("textarea#message").focus();
			$("label#lblMessage").css('color','red');
			return false;
		}
		
		$("img#loadingImage").css('display','');
	
		var dataString = 'name=' + name + '&email=' + email + '&message=' + message;
		//alert(dataString);return false;
		//alert(global['base']);return false;
		
		
		//post form using AJAX, if successfull then change button text and disallow submit again
		$.ajax({
			type: "POST",
			url: global['base']+"contact/email_form",
			data: dataString,
			success: function() 
			{
			
			  $("input#name").val('');
			  $("input#email").val('');
			  $("textarea#message").val('');
			  
			  $("img#loadingImage").css('display','none');
			  
			  $("#submitbutton").attr('value','Message Sent Successfully!');
			  
			
			}
		});
		return false;
	});
	
	//validate form on blur
	$("input#name").blur(function() 
	{
		
		var name = $("input#name").val();
		
		if (name == '')
		{
			$("label#lblName").css('color','red');		
		}
		else
		{
			$("label#lblName").css('color','');
		}
		
	});
	
	$("input#email").blur(function()
	{
		var email = $("input#email").val();
		
		if (email == '')
		{
			$("label#lblEmail").css('color','red');
		}
		else
		{
			$("label#lblEmail").css('color','');
		}
		
	});
	
	$("textarea#message").blur(function()
	{
		var message = $("textarea#message").val();
		
		if (message == '')
		{
			$("label#lblMessage").css('color','red');
		}
		else
		{
			$("label#lblMessage").css('color','');
		}
		
	});
	
	
});
	
//animations for home page

var changeImageTimeout = null;

function changeImage()
{
	if ( changeImageTimeout != null ) clearTimeout(changeImageTimeout);
	var activePanel = $('.panel-active').attr('id');
	if (activePanel == 'wind')
	{
		nextPanel = 'voltaic';
		topMove = '167px';
	}
	else 
	{
		nextPanel = $('#' + activePanel).next().attr('id');
		topMove = '+=128px';
	}
		
	var hillValues = $('#' + nextPanel).attr('title').split(','); 	//this tells where the hills will move on next transition using the title attribute
		
	$('#ad_txt,#' + activePanel).wait(3).then.animate({				
        left: '-385px'												//this moves icon and text off screen to the right
    },
    750,
    function() {
    	$('#' + activePanel + '_holder').css('display','none');		//This hides the current panels description text
		$('.panel-active').attr('class','panel');					//This cycles the panels classes between each animation, changing the active Panel				
		$('#' + nextPanel).attr('class','panel-active');
		$('#' + nextPanel + '_holder').removeAttr("style");			//If the next panel's description text is off, this will make it visible
		$('#ad_hm').attr('class', nextPanel);
        $('#ad_txt').animate({
            left: '334px'  											//this returns active panel, icon, and text to the screen
        },
        750);
        
		$('#' + nextPanel).animate({
            left: '100px' 											//controls the icons location
        },
        750);
		$('#arrow').animate({ top: topMove }, { duration: 750, queue: false });
		$('#hill1').animate({ left: hillValues[0]+'px' }, { duration: 750, queue: false });
		$('#hill2').animate({ left: hillValues[1]+'px' }, { duration: 750, queue: false });
		$('#hill3').animate({ left: hillValues[2]+'px' }, { duration: 750, queue: false });
		$('#hill4').animate({ left: hillValues[3]+'px' }, { duration: 750, queue: false });
    });
	changeImageTimeout = setTimeout('changeImage()',9000);
	}
	
function stopChangeImage(){
	if ( changeImageTimeout != null ) clearTimeout(changeImageTimeout);
	changeImageTimeout = null;
	}

/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

 (function($) {

    $.fn.hint = function(blurClass) {
        if (!blurClass) {
            blurClass = 'blur';
        }

        return this.each(function() {
            // get jQuery version of 'this'
            var $input = $(this),

            // capture the rest of the variable to allow for reuse
            title = $input.attr('title'),
            $form = $(this.form),
            $win = $(window);

            function remove() {
                if ($input.val() === title && $input.hasClass(blurClass)) {
                    $input.val('').removeClass(blurClass);
                }
            }

            // only apply logic if the element has the attribute
            if (title) {
                // on blur, set value to title attr if text is blank
                $input.blur(function() {
                    if (this.value === '') {
                        $input.val(title).addClass(blurClass);
                    }
                }).focus(remove).blur();
                // now change all inputs to title
                // clear the pre-defined text when form is submitted
                $form.submit(remove);
                $win.unload(remove);
                // handles Firefox's autocomplete
            }
        });
    };

})(jQuery);

/**
* Google Analytics code
**/
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-8789986-2']);
  _gaq.push(['_setDomainName', 'none']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
