/*-----------------------------------------------------------------------------------*/
/*  Fire it up!
/*-----------------------------------------------------------------------------------*/

jQuery(document).ready(function() {

/*-----------------------------------------------------------------------------------*/
/*  Tabs
/*-----------------------------------------------------------------------------------*/
  
	if (jQuery('#tabs').length > 0){
		jQuery("#tabs").tabs();
    }

/*-----------------------------------------------------------------------------------*/
/*  Testimonials
/*-----------------------------------------------------------------------------------*/

	if (jQuery('#testimonialsinner').length > 0){
		jQuery('#testimonialsinner').cycle({ 
	        fx:     'scrollUp', 
	        speed:  750, 
	        timeout: 5000, 
	        pause:1,
	        cleartypeNoBg:true
	    });
    }

/*-----------------------------------------------------------------------------------*/
/*  Clickable Elements
/*-----------------------------------------------------------------------------------*/

	jQuery('.clickable').live('click', function() {
        if (jQuery('a', this).attr('target')) {
            window.open(jQuery('a', this).attr('href'), jQuery('a', this).attr('target'));
        } else {
            location.href = jQuery('a', this).attr('href');
        }
        return false;
    });
    
/*-----------------------------------------------------------------------------------*/
/*  Sliding Elements
/*-----------------------------------------------------------------------------------*/
	
    jQuery('div.service').hover(function() {
        var newmargintop = jQuery(this).innerHeight() - jQuery('.caption', this).outerHeight(); 
        jQuery('.caption', this).stop().animate({'margin-top':newmargintop});
    }, function() {
        var newmargintop = jQuery(this).innerHeight() - jQuery('.caption h4', this).outerHeight();
        jQuery('.caption', this).stop().animate({'margin-top':newmargintop});
    });
    
/*-----------------------------------------------------------------------------------*/
/* Accordion
/*-----------------------------------------------------------------------------------*/
	
	jQuery('div#left dl dt').click( function () {
		jQuery('div#left dl dd').removeClass('open');
		jQuery(this).next().addClass('open').slideToggle('800');
		jQuery('div#left dl dd:not(.open)').slideUp('200');
	});
    
/*-----------------------------------------------------------------------------------*/
/*  Back to Top Link
/*-----------------------------------------------------------------------------------*/
    
    /* Set variables locally for increased performance */
	var scroll_timer;
	var displayed = false;
	var jQuerymessage = jQuery('#backtotop a');
	var jQuerywindow = jQuery(window);
	var top = jQuery(document.body).children(0).position().top;
 
	/* React to scroll event on window */
	jQuerywindow.scroll(function () {
		window.clearTimeout(scroll_timer);
		scroll_timer = window.setTimeout(function () { // Use a timer for performance
			if(jQuerywindow.scrollTop() <= top) // Hide if at the top of the page
			{
				displayed = false;
				jQuerymessage.fadeOut(500);
			}
			else if(displayed == false) // Show if scrolling down
			{
				displayed = true;
				jQuerymessage.stop(true, true).show().click(function () { jQuerymessage.fadeOut(500); });
			}
		}, 100);
	});
	
	jQuery('a[href=#pagetop]').click(function(){
        jQuery('html, body').animate({scrollTop:0}, 'medium');
        return false;
    });
    
/*-----------------------------------------------------------------------------------*/
/*  Cross-Browser
/*-----------------------------------------------------------------------------------*/

    if (jQuery.browser.msie && jQuery.browser.version < 9.0){
		jQuery('div#links ul li').last().addClass('last-child');
	}
    
/*-----------------------------------------------------------------------------------*/
/*  That's it! All done :)
/*-----------------------------------------------------------------------------------*/

});	
