// DOM Loaded 
$(function(){ 
     
    //init js styles 
    $('body').addClass('hasJS'); 


// -----------------------------------------------------------------------------------------------------
// homepage rotator 
// -----------------------------------------------------------------------------------------------------

    $('#slide_main').cycle({ 
        fx:'scrollDown', 
        easing: 'swing', 
        inDelay:    250, 
		speed: 'fast',
        drop:       40, 
        timeout:    4000,
        pause:      true,
        pager:      '#slide_thumbs',
	    pagerEvent: 'mouseover' ,
		
		pagerAnchorBuilder: function(idx, slide) {
            return '#slide_thumbs li:eq(' + (idx) + ') a';
        }
    });
	
	    $('#slide_units').cycle({ 
        fx:'scrollDown', 
        easing: 'swing', 
        inDelay:    250, 
		speed: 'fast',
        drop:       40, 
        timeout:    700000000000000000,
        pause:      true,
        pager:      '#slide_thumbs',
	    pagerEvent: 'mouseover' ,
		
		pagerAnchorBuilder: function(idx, slide) {
            return '#slide_thumbs_units li:eq(' + (idx) + ') a';
        }
    });
		
	$('#ngg-gallery-1-66').cycle({ 
        fx:'scrollDown', 
        easing: 'swing', 
        inDelay:    250, 
		speed: 'slow',
        drop:       40, 
        timeout:    5000,
    });
	
	$('#text').cycle({ 
        fx:'fade', 
        timeout:    10000,
    });
		
		
		
    $(".scroll").click(function(event){
        //prevent the default action for the click event
        event.preventDefault();
 
        //get the full url - like mysitecom/index.htm#home
        var full_url = this.href;
 
        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
        var parts = full_url.split("#");
        var trgt = parts[1];
 
        //get the top offset of the target anchor
        var target_offset = $("#"+trgt).offset();
        var target_top = target_offset.top;
 
        //goto that anchor by setting the body scroll top to anchor top
        $('html, body').animate({scrollTop:target_top}, 500);
    });	
	
	
	//
	// form labels
	//
	
	$('form#info .slider label').each(function(){
	var labelColor = '#999';
	var restingPosition = '5px';

	// style the label with JS for progressive enhancement
	$(this).css({
		'color' : labelColor,
		 	'position' : 'absolute',
	 		'top' : '6px',
			'left' : restingPosition,
			'display' : 'inline',
    	               'z-index' : '99'
	});

	// grab the input value
	var inputval = $(this).next('input').val();

	// grab the label width, then add 5 pixels to it
	var labelwidth = $(this).width();
	var labelmove = labelwidth + 5;

	//onload, check if a field is filled out, if so, move the label out of the way
	if(inputval !== ''){
		$(this).stop().animate({ 'left':'-'+labelmove }, 1);
	}    	

	// if the input is empty on focus move the label to the left
	// if it's empty on blur, move it back
	$('input').focus(function(){
		var label = $(this).prev('label');
		var width = $(label).width();
		var adjust = width + 5;
		var value = $(this).val();

		if(value == ''){
			label.stop().animate({ 'left':'-'+adjust }, 'fast');
		} else {
			label.css({ 'left':'-'+adjust });
		}
	}).blur(function(){
		var label = $(this).prev('label');
		var value = $(this).val();
		if(value == ''){
			label.stop().animate({ 'left':restingPosition }, 'fast');
		}
	});
})

 
});
 
