// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~ Global Vars ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~ Drop downs on the menu navbar ~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function jsddm_open(){
	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = jQuery(this).find('ul').eq(0).css('visibility', 'visible');
}

function jsddm_close(){
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer(){
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer(){	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;
	}
}

jQuery(document).ready(function(){
	jQuery('#jsddm > li').bind('mouseover', jsddm_open);
	jQuery('#jsddm > li').bind('mouseout',  jsddm_timer);

	jQuery('delete-button').click(function() {
	  	if (!confirm('Are you sure you wish to delete this entry?')){
			return false;
		}
	});
});

document.onclick = jsddm_close;

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~ Cufon - Font Replacment ~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cufon.replace('h1', { fontFamily: 'Helvetica' });
Cufon.replace('.grey_boxes h2', { fontFamily: 'Helvetica' });

$.noConflict();
jQuery(document).ready( function(){

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// ~~~~~~~~~~~~~~~~~~~~~~ Default Values and Clearing for Forms ~~~~~~~~~~
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	jQuery('#password-clear').show();
	jQuery('#password-password').hide();

	jQuery('#password-clear').focus(function() {
	    jQuery('#password-clear').hide();
	    jQuery('#password-password').show();
	    jQuery('#password-password').focus();
	});

	jQuery('#password-password').blur(function() {
	    if(jQuery('#password-password').val() == '') {
	        jQuery('#password-clear').show();
	        jQuery('#password-password').hide();
	    }
	});

	jQuery('.default-value').each(function() {
	    var default_value = this.value;
	    jQuery(this).css('color', '#666'); // this could be in the style sheet instead
	    //jQuery(this).css('font-size', '20px'); // this could be in the style sheet instead
	    jQuery(this).focus(function() {
	        if(this.value == default_value) {
	            this.value = '';
	            jQuery(this).css('color', '#333');
	            //jQuery(this).css('font-size', '12px'); // this could be in the style sheet instead
	        }
	    });
	    jQuery(this).blur(function() {
	        if(this.value == '') {
	            jQuery(this).css('color', '#666');
	            this.value = default_value;
	        }
	    });
	});

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// ~~~~~~~~~~~~~~~~~~~~~~ Slider ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	jQuery('#slider2').anythingSlider({
		width               : 500,        // if resizeContent is false, this is the default width if panel size is not defined
		height              : 350,        // if resizeContent is false, this is the default height if panel size is not defined
		resizeContents      : false,      // If true, solitary images/objects in the panel will expand to fit the viewport
		startStopped        : false,      // If autoPlay is on, this can force it to start stopped
		autoPlay            : true,		 // This turns off or on the entire slideshow FUNCTIONALY, not just if it starts running
		delay				: 12000,       // How long between slide transitions in AutoPlay mode
		animationTime		: 700        // How long the slide transition takes
		//navigationFormatter : formatText  // Format navigation labels with text
	});

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// ~~~~~~~~~~~~~~~~~~~~~~ Logos Fade ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	jQuery('.logobox .logos');
	setInterval(function(){
		jQuery('.logobox .logos').filter(':visible').fadeOut(1000,function(){
			if(jQuery(this).next('div.logos').size()){
				jQuery(this).next().fadeIn(1000);
			}
			else{
				jQuery('.logobox .logos').eq(0).fadeIn(1000);
			}
		});
	},7000);

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// ~~~~~~~~~~~~~~~~~~~~~~ Testimonials Fade ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	jQuery('#testimonials .slide');
	setInterval(function(){
		jQuery('#testimonials .slide').filter(':visible').fadeOut(1000,function(){
			if(jQuery(this).next('li.slide').size()){
				jQuery(this).next().fadeIn(1000);
			}
			else{
				jQuery('#testimonials .slide').eq(0).fadeIn(1000);
			}
		});
	},6000);

	jQuery('#testimonials').click(function(e){
		window.location = 'testimonials';
	});


}); // Doc ready


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~ Global Functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function addHover()
{
	var nav = document.getElementById('nav');
	nav.className='hover';
}

function undoHover()
{
	var nav = document.getElementById('nav');
	nav.className='';
}

function clearSearch()
{
	var search = document.getElementById('s');
	if (search.value == 'Search')
	{
		search.value='';
	}
}
