$(document).ready(function(){		
	
	
	$("a.fancybox").fancybox({
		'padding'		: 0
	});	
	
	
	
	$('.two_col_list').easyListSplitter({ 
		colNumber: 2
	});
	
	$(function() {
		var hash=location.hash;
		if (hash){
			$.scrollTo(hash,1500);
		}
	});
	
	$(function() {
		$(".inputtext").focus(function(){
			_holdText = $(this).attr("rel");
			if ($(this).val() == _holdText) {
			 	$(this).val("");
			 	$(this).removeClass("textdark");
			} else {
				$(this).addClass("textdark");
			}
		}).blur(function(){
			if ($.trim($(this).val()) == "") {
			 	$(this).val(_holdText);
				$(this).removeClass("textdark");
		  	} else {
		  		$(this).addClass("textdark");
		  	}
		});
	});
	
	
	
	
	$(".inputtext").each(function(){
		if($(this).val()!=$(this).attr("rel")) {
			$(this).addClass("textdark");
		}
	});	
	
	$('#customers').masonry({
    	columnWidth: 230, 
    	itemSelector: '.customerblock' 
	});
	
	$(function(){
	// Datepickers
		$('#dateselect').datepicker({inline: true,dateFormat: 'm/d/yy'});
	});
	
	$(".hcdot a").bind('click', imageClickChanger);
	
});

startHeaderRotation = function() {
  interval = setInterval('changeimage()',7500);
}

imageClickChanger = function() {

	clearInterval(interval);		

	var _gotoImage = $(this).attr('rel');	
	
	var _offset = $(this).attr('tracker');
	
	$(".hcdot a").unbind('click', imageClickChanger);
	
	$.get('/embeds/ajaxfeature/'+parseInt(_offset-1), function(data) {
		$('#featureimage').append(data);
		
		$('#'+_currentImage).stop().animate({width:0}, 500, function() {
		
			$('#'+_currentImage).remove();
			
			_currentImage = _gotoImage;
			
			$('#headercontrol_currentoffset').text(parseInt(_offset-1));
			
			$(".hcdot a").each(function(){
				if($(this).attr("rel")==_gotoImage) {
					$(this).addClass('on');
				} else {
					$(this).removeClass('on');
				}
			});		
	 	
	 		$(".hcdot a").bind('click', imageClickChanger);

		});

	});
}


changeimage = function() {

	$(".hcdot a").unbind('click', imageClickChanger);
	
	var _totalCount = parseInt($('#headercontrol_total').text());
	
	var _currentOffset = parseInt($('#headercontrol_currentoffset').text());
	
	var _tempcount = _currentOffset+1;
	
	if (_totalCount == _tempcount) {
		var _newOffset = 0;
	} else {
		var _newOffset = _currentOffset + 1;
	}

	$.get('/embeds/ajaxfeature/'+_newOffset, function(data) {
		$('#featureimage').append(data);
		
		$('#'+_currentImage).stop().animate({width:0}, 500, function() {
		
			$('#'+_currentImage).remove();
			
			_gotoImage = $('#featureimage').find('.imagedisplay').attr('id');
			
			_currentImage = _gotoImage;
			
			$('#headercontrol_currentoffset').text(_newOffset);
			
			$(".hcdot a").each(function(){
				if($(this).attr("rel")==_gotoImage) {
					$(this).addClass('on');
				} else {
					$(this).removeClass('on');
				}
			});		
	 	
	 		$(".hcdot a").bind('click', imageClickChanger);

		});
	
	});
	
	//$('#headercontrol_ajaxreturn').load('/_embeds/_ajax_header_image/'+_newOffset, function() {
  			//updateHomeImage(_currentOffset,_newOffset);
	//});
}




