// ************* DEFINE CUFON TEXT REPLACMENTS

// Main menu links
Cufon.replace('.menu-item a, .menu-item-active a, a.submenu-link, a.submenu-link-active', { hover:true, fontFamily: 'Calibri' });

// Page content headings
Cufon.replace('.page-content h2, .page-content h3, .page-content h4, .page-content h5', { hover:true, fontFamily: 'Calibri' });

// Footer, Sidebar, and gallery headings
Cufon.replace('#footer-tabs h2, #gallery h2, .sidebar-item h2', { hover:true, fontFamily: 'Calibri-bold' });



// make jQuery no conflic with other APIs
var $j = jQuery.noConflict();

// extend jquery 
	$j.fn.wait = function(time, type) {
        time = time || 500;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $j(self).dequeue();
            }, time);
        });
    };


(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

// ************* DEFINE jQuery functions
$j(document).ready(function(){

	/* prelaod the images */
	jQuery.preLoadImages("","");

	// Define easing type
	jQuery.easing.def = 'easeOutSine';
	
	// ************* DEFINE - Roll over events for any image tagged with .over
	$j('img.over').each(function() 
	{
    	var t = $j(this);
    	var src = t.attr('src'); // initial src
    	var path = src.substring(0,src.lastIndexOf('/')); // path to file
    	var filename = src.substring(src.lastIndexOf('/'), src.lastIndexOf('.')); // let's get file name without extension
    	
    	t.hover(function(){
        	$j(this).attr('src', path + filename + '-over.' + /[^.]+$/.exec(src)); //last part is for extension 
        	
        	//alert(path+filename+ '-over.' + /[^.]+$/.exec(src));
        	
    	}, function(){
        	$j(this).attr('src', path + filename + '.' + /[^.]+$/.exec(src)); //removing '-over' from the name
        	
        	//alert(path + filname + '.' + /[^.]+$/.exec(src));
    	});
	});
	
	
	/*
		Add carousel functionality
	*/
    $j(".nonCircular .gallery-carousel").jCarouselLite({
    	scroll: 1,
    	visible: 4,
    	speed: 800,
    	start: 0,
        btnNext: ".nonCircular .next",
        btnPrev: ".nonCircular .prev",
        circular: false,
        vertical: true
    });
    
    //alert($j("li.gallery-item").length)
    
    if($j("li.gallery-item").length > 4) 
    {
    	$j("div.next").removeClass("disabled");
    }
    

	
	// add printing
	/*$j("#print-page").click(function(event)
	{
		$j("#content-overlay").jqprint();
	});*/
	
	
	// ************* DEFINE - lawyers page add alpha and roll overs to thumbs
	/*$j("div.lThumb").hover(
		
		function () {
			$j(this).stop(true, true).fadeTo("fast", 1.0);
      	}, 
      	function () {
        	$j(this).stop(true, true).fadeTo("fast", 0.5);
      	}
	);*/
	
	$j("li.menu-item").mouseenter(function(event)
	{
		var sub = $j(this).find("ul.cci-submenu");
		sub.stop(true, true).fadeIn("normal");
	});
	
	$j("li.menu-item").mouseleave(function(event)
	{
		var o = $j(this).attr("class");
		if(o.indexOf('open-menu') == -1) {
			var sub = $j(this).find("ul.cci-submenu");
			sub.stop(true, true).hide();//fadeOut("normal");
		}
	});
	
	$j('li.open-menu').each(function() 
	{
		var sub = $j(this).find("ul.cci-submenu");
		sub.stop(true, true).show();
	});
	
});

function linkTitle(response) {
	var str = response;
	var s = str.indexOf("<h3>");
	var e = str.indexOf("</h3>");
	var linktag = str.substring(s+4,e);
	return linktag;
}


/* function - loops headline on the homepage */
var wait = setInterval(showHeadline,6000);
var storyID = 0;
function showHeadline() 
{
	// get object to fade out
	var f_out = "#headline-" + storyID;
	
	// get the id of object to fade in
	if(storyID >= 3) storyID = 0;
	else storyID ++;
	
	// get object to fade in
	var f_in = "#headline-" + storyID;

	$j(f_out).fadeOut(1000,function() {
		// Animation complete now fade in new story
		$j(f_in).fadeIn("fast");
	});
}

function initHeadline()
{
	// ************* DEFINE - home page fadein headline and headline-back
	/*$j("#headline-back").wait(1000).slideDown(1000,function() {
		// Animation complete now fade in new story
		$j("#headline-1").find('p').wait(500).fadeIn("fast");
	});*/
	
	$j("#headline-0").find('p').wait(1500).fadeIn("fast");
}
	
	
	
	
	
	
	
	
