

function scrollTop(offset){
	var offset = (offset) ? offset : 0;
	$('html, body').animate({scrollTop:offset}, 'slow'); 
}

// STRING FUNCTIONS
function checkString(path,arrayNumber) {
	var newPath = trim(path);
	if(arrayNumber == 1) {
		if (!validate(newPath)){
			return false;
		} else {
			return newPath;	
		}
	} else {
		if(newPath.length<1) return ""; else return newPath
	}
}

function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 

    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}

function validate(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   //var address = newPath;
   if(reg.test(address) == true) {
      //alert('Invalid Email Address');
      return address;
   }
}
// END STRING FUNCTIONS


// Hero Slider functions
function slideShow(){
	$.get("handlers/get_slideshow.php", function(msg){
		$("#hero_slider").html(msg);
		$('#hero_slider').cycle({ 
			fx:        'scrollLeft',
			direction: 'left', // one of up|down|left|right  default=left
			timeout: 0,
			speed: 	250,
			next:   '#next', 
			prev:   '#prev'
		});
		
		// PAGE global var found in history.functions.js
		if(PAGE=='home')
			openSlider();
		else
			squeezeSlider();

	});
	
	// main hero arrows
	$(".hero_arrow").each(function(){
		// opacity level
		var level = .9;
		$(this).animate({opacity:level});
		
		$(this).hover(function(){
			$(this).stop().animate({opacity:1});
		}, function(){
			$(this).stop().animate({opacity:level});
		});
		
	});
	
	// setup button for opening and closing hero slider
	$("#close_slider").click(function(){
		if($('#hero_wrapper').height()>150) {
			squeezeSlider();
		} else {
			openSlider();
		}
	});
	
}

// slider "PORTFOLIO" Functions
function squeezeSlider(){
	$('#hero_bar').attr('src', IMAGES+'view-bar.png');
	$('#hero_wrapper').animate({height:150});
	$('.hero_arrow').hide();
}

function openSlider(){
	$('#hero_bar').attr('src', IMAGES+'hide-bar.png');
	$('#hero_wrapper').animate({height:540});
	$('.hero_arrow').fadeIn();	
}
// END slider "PORTFOLIO" Functions


// jquery preloader function. 
(function($) {
	var cache = [];
	$.preLoadImages = function(image_array, callback) {
		if(typeof image_array == 'object' && image_array.length){
			// we have an array
			var images = image_array;
		} else if(typeof image_array == 'string'){
			// we have a string.  make an array of the csv info
			var images = image_array.split(',');
		} else {
			// return fals if 
			return false;
		}
		
		var count = images.length;
		for (var i = count; i--;) {
			var cache_image = document.createElement('img');
			cache_image.src = images[i];
			cache.push(cache_image);
		}					
		
		if(typeof callback == 'function'){
			callback.call(this);
		}
							
	}
})(jQuery)
