//Animated Scroll
function goto(divname){
	var targetOffset = $("#"+divname).offset().top;
	$('html,body').animate({ scrollTop: targetOffset }, 500 );
}

//Coda Slider
$().ready(function() {
       $('#main-slider').codaSlider({
           autoSlide: true,
           autoSlideInterval: 7000,
		   slideEaseDuration: 1000,
		   dynamicTabs: false,
           autoSlideStopWhenClicked: true,
           autoHeightEaseFunction: "easeInOutCubic",
           slideEaseFunction: "easeInOutCubic"
       });
   });

//Smooth Hovers
$(document).ready(function(){
   	$(".bg_hover").mouseover(function(){
       		$(this).stop().animate({ backgroundColor: "#2aa0ee" }, 350);
   		}).mouseout(function(){
   			$(this).stop().animate({ backgroundColor: "#E1CBB5" }, 350);
    	});
	
	$(".link_bg").mouseover(function(){
       		$(this).stop().animate({ backgroundColor: "#f0f0f0",color: "#000" }, 350);
   		}).mouseout(function(){
   			$(this).stop().animate({ backgroundColor: "#fff",color: "#0066AA" }, 350);
    	});
	
	$(".img_lst_bg").mouseover(function(){
       		$(this).stop().animate({ backgroundColor: "#f0f0f0" }, 350);
   		}).mouseout(function(){
   			$(this).stop().animate({ backgroundColor: "#fff" }, 350);
    	});
		
	$(".link_hover").mouseover(function(){
       		$(this).stop().animate({ color: "#000" }, 350);
   		}).mouseout(function(){
   			$(this).stop().animate({ color: "#0066AA" }, 350);
    	});
	
	$(".text_input, .text_area").mousedown(function(){
       		$(this).stop().animate({ backgroundColor: "#f0f0f0" }, 350);
   		}).mouseout(function(){
   			$(this).stop().animate({ backgroundColor: "#fff" }, 350);
    	});
	
	$("#featured_1").mouseover(function(){
       		$(this).stop().animate({ backgroundColor: "#dd3700",color: "#fff" }, 350);
   		}).mouseout(function(){
   			$(this).stop().animate({ backgroundColor: "#f1f1f1",color: "#000" }, 350);
    	});
	
	$("#featured_2").mouseover(function(){
       		$(this).stop().animate({ backgroundColor: "#ff6f00",color: "#fff" }, 350);
   		}).mouseout(function(){
   			$(this).stop().animate({ backgroundColor: "#f1f1f1",color: "#000" }, 350);
    	});
	
	$("#featured_3").mouseover(function(){
       		$(this).stop().animate({ backgroundColor: "#ffa600",color: "#fff" }, 350);
   		}).mouseout(function(){
   			$(this).stop().animate({ backgroundColor: "#f1f1f1",color: "#000" }, 350);
    	});
});

(function ($) {
    $.fn.cross = function (options) {
       return this.each(function (i) { 
           var $$ = $(this);
           
           var target = $$.css('backgroundImage').replace(/^url|[\(\)'"]/g, '');

           $$.wrap('<span style="position: relative;"></span>')
               .parent()
               .prepend('<img>')
               .find(':first-child')
               .attr('src', target);
           if ($.browser.msie || $.browser.mozilla) {
               $$.css({
                   'position' : 'absolute', 
                   'left' : 0,
                   'background' : '',
                   'top' : this.offsetTop
               });
           } else if ($.browser.opera && $.browser.version < 9.5) {
                  
               $$.css({
                   'position' : 'absolute', 
                   'left' : 0,
                   'background' : '',
                   'top' : "0"
               });
           } else { // Safari
               $$.css({
                   'position' : 'absolute', 
                   'left' : 0,
                   'background' : ''
               });
           }

           $$.hover(function () {
               $$.stop().animate({
                   opacity: 0
               }, 350);
           }, function () {
               $$.stop().animate({
                   opacity: 1
               }, 350);
           });
       });
   };
        
})(jQuery);

$(window).bind('load', function () {
   $('img.fade').cross();
});

function mainmenu(){
	$(" #navigation ul ").css({display: "none"}); // Opera Fix
	$("#navigation li").hover(function(){
		$(this).find('ul:first:hidden').slideDown(200);
	},function(){
		$(this).find('ul:first').slideUp(200);
	});
}

//Collapsible Panel
(function($) {
    $.fn.extend({
        collapsiblePanel: function() {
            // Call the ConfigureCollapsiblePanel function for the selected element
            return $(this).each(ConfigureCollapsiblePanel);
        }
    });

})(jQuery);

function ConfigureCollapsiblePanel() {
    $(this).addClass("ui-widget");

    // Wrap the contents of the container within a new div.
    $(this).children().wrapAll("<div class='collapsibleContainerContent ui-widget-content'></div>");

    // Create a new div as the first item within the container.  Put the title of the panel in here.
    $("<div class='collapsibleContainerTitle ui-widget-header'><div>" + $(this).attr("title") + "</div></div>").prependTo($(this));

    // Assign a call to CollapsibleContainerTitleOnClick for the click event of the new title div.
    $(".collapsibleContainerTitle", this).click(CollapsibleContainerTitleOnClick);
}

function CollapsibleContainerTitleOnClick() {
    // The item clicked is the title div... get this parent (the overall container) and toggle the content within it.
    $(".collapsibleContainerContent", $(this).parent()).slideToggle();
}

$(document).ready(function(){
	mainmenu();
	$(".collapsibleContainer").collapsiblePanel();
});

//Cufon fonts
var $disable_cufon = jQuery("meta[name=disable_cufon]").attr('content');
if($disable_cufon !='true') {
	Cufon.replace('h1,h2,h3,h4,h5,h6,strong,.collapsibleContainerTitle', { hover: 'true' });
}
