/**
 * Copyright Nick Obrien, all written code!
 * Please ask/notice for using..
 */
$(document).ready(function(){
	// Cufon replace
	//Cufon.replace('h1', { fontFamily: 'TheSans', fontSize: '22px' });
	//Cufon.replace('h2, h3, h4', { fontFamily: 'TheSans' });

	// Init
	alignFooter();

	$(window).resize(function(){
		alignFooter();
	});

	// Input value change
	$('.change_value').each(function(index){

		var el = $(this);

		el.bind('blur', function(){
			if (el.val() == ''){
				el.val(el.attr('title'));
			}
		}).blur();
		
		el.bind('focus', function(){
			if (el.val() == el.attr('title')){
				el.val('');
			}
		});
	});
	
	// Focus field that is requesting focus
	$('.need-focus').focus();
	
	// Calendar slider
	$('#calendar-items').cycle({ 
	    fx:     'fade', 
	    speed:  'fast', 
	    timeout: 0, 
	    next:   '#next2', 
	    prev:   '#prev2' 
	});
	
	//$('#login').hide();
	$('.login-button').click(function(){
		$('#login').slideToggle('slow');
	});
	
	// Use nivoslider for awesome effects
	$(window).load(function() {
	    $('#slider').nivoSlider({
	    	controlNav: false,
	    	slices:12,
	        animSpeed:500,
	        pauseTime:7000,
	    	directionNav: false
	    });
	});
	
});

function alignFooter()
{	
    var wrap_el = $('#wrap');
	var footer_el = $('#footer-wrap');

    if (wrap_el && footer_el)
    {
        var wrap_height = wrap_el.height();
		var footer_height = footer_el.height();
        var window_height = $(window).height();
        var margin = 15;
		
        if ( wrap_height < (window_height - footer_height) )
            margin = parseInt( (window_height - wrap_height - footer_height - 12) );
		
		footer_el.css('marginTop', margin + 'px');
    }
}
