$(document).ready(function() {
	// Drop-in Subnavs
	$('#sf-sub-list').click(function(){
		if($('.sub-vaca').hasClass('open')){
			$('.sub-vaca').removeClass('open').slideUp('fast');
			$('.clicked-sn').removeClass('clicked-sn');
		}
		if($('.sub-list').hasClass('open')){
		$('.sub-list').removeClass('open').slideUp('fast');
		$('.clicked-sn').removeClass('clicked-sn');
		return false;
		} else {
		$('.sub-list').addClass('open').slideDown('slow');
		$(this).parent('li').addClass('clicked-sn');
		return false;
		}
	}); 
	$('#sf-sub-vaca').click(function(){
		if($('.sub-list').hasClass('open')){
			$('.sub-list').removeClass('open').slideUp('fast');
			$('.clicked-sn').removeClass('clicked-sn');
		}
		if($('.sub-vaca').hasClass('open')){
		$('.sub-vaca').removeClass('open').slideUp('fast');
		$('.clicked-sn').removeClass('clicked-sn');
		return false;
		} else {
		$('.sub-vaca').addClass('open').slideDown('slow');
		$(this).parent('li').addClass('clicked-sn');
		return false;
		}
	}); 
	// Right Nav / Cluster
	$('a.trigger').click(function(){
		if($(this).next('.cluster ul').hasClass('open')){
			$(this).next('.cluster ul').removeClass('open').slideUp('fast');
			$(this).find('span').text('+');
			return false;
		} else {
		$(this).next('.cluster ul').addClass('open').slideDown('slow');
		$(this).find('span').text('-');
			return false;
		}
	});
	    // Fancybox defined
	$("a.fancy").fancybox();
	$("a.frame").fancybox({
            'frameWidth': 860,
            'frameHeight': 420
    }); 
    $("a.full-frame").fancybox({
            'frameWidth': 960,
            'frameHeight': 500,
            'hideOnOverlayClick': true
    });
    // URL Hide
	$(".urlhide").hover(function() {
		$(this).attr('href' , 'http://www.' + $(this).attr('rel'));
	});
		/////////////////////
//Listing Phone hide/show
////////////////////
			function initPhone() {
				$('a.showphone').click(function(x) {
					x.preventDefault();
						$(this).next('.printphone').removeClass('printphone').addClass('viewphone');	
						}
				 );
				}
			$(document).ready(function() {initPhone();
		});

function logclick(url)
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Purpose: Asynchronous AJAX call to logclick to insert click
	Date		Name        	Description
	8/25/06 	erbjorkman  	Initial creation
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    {
	  //known bug. ajax agent drops querystring params after an ampersand. querystrings must 
	  //custom encoded on the client then similarly decoded on the server
      url = replace(url,'&','||');
      //alert(url);
      agent.call('','logclick','',url);
      //agent.call('','logclick','callback_logclick',url);
    }
    function replace(string_source,find_string,replace_string)
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Purpose: String replace 
	Date     	Name        	Description
	8/25/06 	erbjorkman  	Initial creation
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    {
		while(string_source.indexOf(find_string) > -1)
		{
		string_source = string_source.replace(find_string,replace_string);
		}
		return string_source;
	}    

});


