/**
 * Copyright Nick Obrien, all written code!
 * Please ask/notice for using..
 */
$(document).ready(function(){
	/*
	// Cufon replace
	Cufon.replace('h1', { fontFamily: 'Negotiate' });
	Cufon.replace('h2, h3', { fontFamily: 'Negotiate' });
	Cufon.replace('ul#header-menu a', { fontFamily: 'Negotiate', hover: true });
	Cufon.replace('div#page-title p', { fontFamily: 'Negotiate' });

	$('div#page-title-content p').rotate(90);
	$('div#page-title-content span').remove();
	$('div#page-title-content p').each(function(i){
		if (i!=0){
			if ($.browser.msie) $(this).css('margin-top','-20px');
			else $(this).css('margin-top','-30px');
		}
	});
	*/

	// Input value change
	$('.change_clear_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('');
			}
		});
	});

	if ($('div#footer-stick') != undefined)
	{
		footer_height = $('div#footer').height();
		footer_margintop = parseInt($('div#footer').css('margin-top'));

		// Do correction
		footer_correction = footer_height + footer_margintop;

		$('div#footer-stick').css({
			'height' : footer_correction+'px',
			'min-height' : footer_correction+'px'
		});
		$('div#page-holder').css('margin-bottom','-'+footer_correction+'px');
	}

	// Wings
	align_wings();
	
	// Add a listener
	$(window).resize(function() {
		align_wings();
	});

	// Focus field that is requesting focus
	$('.need-focus').focus();
	
	// Rotate text
	rotate_title();
	
	//setTimeout('setFont()', 5000);
	
});

function setFont()
{
	$('div#page-title-content div.rotateme').css('font-family', 'Negotiate, Helvetica, Arial');
}

function align_wings ()
{
	var targets = $('div#page-title, div#grey-bar-extend');
    var content_width = $('div.container:first').width();

    if (content_width > 0)
    {
        var window_width = $(window).width();
        var correctedwidth = 0;

		correctedwidth = parseInt((window_width-content_width)/2)+1;

        // Set attributes and show wrap element
        targets.css('width', correctedwidth + 'px');
		
		targets.show();

		return true;
    }

	return false;
}

function rotate_title ()
{

	var rotateWidth = $('div#page-title-content div.rotateme').width();
	var rotateHeight = $('div#page-title-content div.rotateme').height();
	
	var horizontalHalf = Math.round(rotateWidth/2)-50;
	var verticalHalf = Math.round(rotateWidth/2);
	
	$('div#page-title-content div.rotateme').css('top', verticalHalf);
	$('div#page-title-content div.rotateme').css('right', '-'+horizontalHalf+'px');
	
	$('div#page-title-content div.rotateme').rotate(90);
	
}

