/**
 * Form Enhancements
 */
	function inputClear (el) {
		var i = '#'+el;
		if($(i).attr('value') == $(i).attr('title')) {$(i).attr('value','');}
		formFocusAdd(el);
	}
	function inputReset (el) {
		var i = '#'+el;
		if($(i).attr('value')== '') {$(i).attr('value',$(i).attr('title'));}
		formFocusRemove(el);
	}
	function formFocusAdd (el) {
		$('#'+el).addClass('focussed');
	}
	function formFocusRemove (el) {
		$('#'+el).removeClass('focussed');
	}
	function within (array,val) {
		for(var i in array) {
			if(array[i]==val) {
				return true;
			}
		}
		return false;
	}
	function enhanceForms () {
		$("input[type='text']").each(function(){
			$(this).bind({
				click:	function() { inputClear($(this).attr('id')); },
				focus:	function() { inputClear($(this).attr('id')); },
				blur:	function() { inputReset($(this).attr('id')); }
			});
		});
	}

/**
 * Button Enhancements
 */
	function enhanceButtons () {
		$('.button').bind({
			mouseover:	function(){$(this).attr('src',url+'images/btn.send_over.jpg');},
			mouseout:	function(){$(this).attr('src',url+'images/btn.send_up.jpg');}
		});
		$('#user-data form').submit(function(){
			return false;
		});
		$('#user-actions input').click(function(){
			$('#user-data form').submit();
			return false;
		});
	}


var url			= window.location.protocol + "//" + window.location.host + "/";
var initialised	= false;

// Run Functions
$(document).ready(function(){
	enhanceForms();				// refactored

	if($('#login-form').length > 0){
		$('#login-form #submit').mouseover(function(){
			$(this).css({'background-position':'left -45px'});
		});
		$('#login-form #submit').mouseout(function(){
			$(this).css({'background-position':'left top'});
		});
	}

	if($('#calendar-container-manager').length > 0){
		$('#calendar-container-manager #submit').mouseover(function(){
			$(this).css({'background-position':'left -45px'});
		});
		$('#calendar-container-manager #submit').mouseout(function(){
			$(this).css({'background-position':'left top'});
		});
	}

	$('#menu ul li a.popup, #footer a.popup, #trailer-container a').each(function(){
		var href = $(this).attr('href').split('/');
			href = href[href.length-2];
		var height = null;
		if($(this).attr('href')=='#') {
			height = 480;
			href = 'video';
		}
		$(this).parent().append('<a href="'+url+'popup/'+href+'/" class="go"></a>');
		switch(href) {
			case 'film-synopsis':
				height = 400;
			break;
			case 'cast-and-crew':
				height = '90%';
			break;
			case 'promo-material':
				height = 400;
			break;
			case 'privacy-policy':
				height = '90%';
			break;
			case 'legal-notice':
				height = '90%';
			break;
			case 'contact-site-design':
				height = 400;
			break;
			case 'links':
				height = 600;
			break;
		}
		$(this).parent().find('a.go').fancybox({
			'width'				: 472,
			'height'			: (height) ? height : '90%',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
		$(this).click(function(){
			$(this).parent().find('.go').click();
			return false;
		});
	});
	$('#contact-submit').hover(function(){
		if($(this).hasClass('hovered')) {
			$(this).css({'background-position':'left top'});
			$(this).removeClass('hovered');
		} else {
			$(this).css({'background-position':'left -45px'});
			$(this).addClass('hovered');
		}
	});
	$('#link-cancel,#link-delete,#link-publish').bind({
		mouseover:function(){
			$(this).addClass('over');
		},
		mouseout:function(){
			$(this).removeClass('over');
		}
	});
	$('#link-delete').click(function(){
		if(confirm('Are you sure you want to delete this link permanently?')) {
			return true;
		}
		return false;
	});
	setTimeout(function(){
		$('.success').fadeOut('slow');
	},2000);
	//$(document).pngFix();

});
