$(document).ready(function() { 
	
	Cufon.replace('#main_nav a', {fontFamily: 'yccfont'});
	Cufon.replace('h2.section_header', {fontFamily: 'yccfont'});
	Cufon.replace('.section_header h2', {fontFamily: 'yccfont'});
	Cufon.replace('#main h2', {fontFamily: 'yccfont'});
	Cufon.replace('h3.section_header', {fontFamily: 'yccfont'});
	Cufon.replace('.section_header h3', {fontFamily: 'yccfont'});
	Cufon.replace('#sidebar h3', {fontFamily: 'yccfont'});
	Cufon.replace('legend', {fontFamily: 'yccfont'});
	
	setSearchFieldStatus();
	$('#searchField').blur(setSearchFieldStatus);
	$('#searchField').focus(function(){
		if($('#searchField').val() == 'search'){
			$('#searchField').val('')
		}
	})
	$("a[href$='.pdf']").addClass("file-pdf");
	$("a[href$='.doc']").addClass("file-doc");
	$("a[href$='.xls']").addClass("file-xls");
	$("a[href$='.zip']").addClass("file-zip");
	$(".file-list a[href^='http://']").addClass("link-external");
	$(".file-list a[href^='http://www.youngcreativechevrolet.com']").removeClass("link-external");
	

	$('#teaser_carousel').addClass('js');
	$('#teaser_carousel ul').xfade({duration: 4000, speed: 1000});
	$('div.required label').append('*');
	
	$(".thumbnail-list a").fancybox(); 
	
	//$('#main_nav li:last').addClass('last-child');
	
	$('#sidebar a').each(function(){
		if(this.href == window.location.href){
			$(this).addClass('active');
		}
		if($(this).attr('rel')){
			$('#menu-item-'+$(this).attr('rel').split(':').pop() ).addClass('active');
		} 
	});
	
	


}); 


function setupTracking(){
	
	var myDomain = window.location.host.toLowerCase();
	$("a[href^='http:']").not("[href*='"+ myDomain + "']")
		.attr('target','_blank')
		.click(function(){
		
		var s=s_gi('gmeuchevyycceu');
		s.tl(this,'e', $(this).text() );
	});
	
	$("a[href$='.pdf']").click(function(){
		var s=s_gi('gmeuchevyycceu');
		s.tl(this,'d', $(this).text() );
	});
	
	
}




// Stuff that can be done a bit later
$(window).load(function(){
	
	setupTracking();
})

function initExternalLinks() {
	var h = window.location.host.toLowerCase();
	$("a[href^='http:']").not("[href*='"+ h +"']").attr('target','_blank');
}

function setSearchFieldStatus(){
	var label = 'search';
	
	if($('#searchField').val() == ''){
		$('#searchField').val(label)
	}
}






/**
 * METHOD: getImgUrl(f,m,i,h,s)
 * 	Generic method that returns the url to a flickr image.
 * 
 * PARAMS:
 * 	f	- STRING Server farm as return by the flickr api.
 * 	m	- STRING Server id as return by the flickr api.
 * 	i	- STRING Image id as return by the flickr api.
 * 	h	- STRING Secret as return by the flickr api.
 * 	s	- STRING Size of the image. Valid values are listed below.
 * 
 * 	*Valid Image Sizes*
 * 
 * 		s		-	small square 75x75
 * 		t		-	thumbnail, 100 on longest side
 * 		m		-	small, 240 on longest side
 * 		(blank)	-	medium, 500 on longest side
 * 		b		-	large, 1024 on longest side (only exists for 
 * 					very large original images)
 * 		o		-	original image, either a jpg, gif or png,
 * 					depending on source format
 * 
 * 
 */
function getFlickrImgUrl(f,m,i,h,s) {
	if (s) {s = '_'+s;} else {s='';};
	var url = 'http://farm'+f+'.static.flickr.com/'
				+ m +'/' + i + '_' + h + s + '.jpg';
	return url;
};/* end imgUrl() */