function open_fullscreen (url, title) {
	window.open(url,title,"width="+(screen.availWidth-0)+",height="+(screen.availHeight-18)+",scrollbars=yes,top=0,left=0,toolbar=no,location=no,directories=no,menubar=no,resizable=no,status=no");
}

$(window).load(function(){
	$('.type-home #photos, #text-page-full #photos #photo').cycle({
		fx:    'fade',
		speed:  2500,
		timeout: 1000
	});
});

$(document).ready(function() {
	$('#password').submit(function() {
		var password = $('input[name="password"]').val();
		$.ajax({
			type: "POST",
			url: "../cms/sproof_dbaccess.php",
			data: { "password" : password },
			success: function(msg){
				if (msg.length == 0) {
					$('input[name="password"]').css('border-color', 'red');
					$('#password label').css('color', 'red');
				} else {
					window.location.replace('../proofing/login.php?gallery'+msg);
				}
			}
		});
		return false;
	});

	$("input, textarea").live('focusin', function() {
		if($(this).attr('data') == $(this).val()) {
			$(this).val('');
		}
	});
	$("input, textarea").live('focusout', function() {
		if ($(this).val() == '') {
			$(this).val($(this).attr('data'));
		} else {
			$(this).css('border-color', '#444');
		}
	});

	$('form').live('submit', function() {
		error = false;
		$('.required').each(function() {
			if ($(this).attr('data') == $(this).val()) {
				$(this).css('border-color', 'red');
				error = true;
			}
		});

		if (error == true) {
			return false;
		}
	});

	$("#videos a").click(function() {
		if ($(this).hasClass('youtube')) {
			$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'			: $(this).attr('data-width'),
				'height'		: $(this).attr('data-height'),
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});

			return false;
		}

		if ($(this).hasClass('vimeo')) {
			$.fancybox({
				'width' : parseInt($(this).attr('data-width')),
				'height' : parseInt($(this).attr('data-height')),
				'href' : 'http://player.vimeo.com/video/' + $(this).attr('data-video'),
				'autoScale' : true,
				'title'	: this.title,
				'transitionIn' : 'none',
				'transitionOut' : 'none',
				'type' : 'iframe',
				'padding' : 0
			});

			return false;
		}

		return false;
	});
	
	var btt = $(".back-to-top");
	if ($(btt).length) {
		if ($(window).height() >= $(document).height()) {
			$(btt).hide();
		} else {
			$(btt).show();
		}
	}
});
