$(document).ready(function(){	

	// initialize SuperBGImage
	$("#background").superbgimage().hide();
	
	
	// Options for SuperBGImage
	$.fn.superbgimage.options = {
		transition: 1, // 0-none, 1-use random transition (0-7)
		transitionout: 1,
		vertical_center: 0,
		preload: 1,
		slideshow: 1, // 0-none, 1-autostart slideshow
		slide_interval: 15000, // interval for the slideshow
		randomimage: 1, // 0-none, 1-random image
		speed: 'slow' // animation speed
	};

	var $menu = $("#menu");
	$menu.delay(600).animate({top: parseInt($menu.css('top'),10) == 0 ? -$menu.outerHeight() : 0});
				
	//var $player = $("div.jp-audio");
	//$player.delay(600).animate({bottom: parseInt($player.css('bottom'),10) == 0 ? -$player.outerHeight() : 0});
	
	var $pageOpen = false;
	
	$("body").supersleight();
		
	$("a[rel=galero], a[rel=galpub], a[rel=galmod]").fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
		
	$("a[rel=video]").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'			: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});
		
		return false;
	});		
	
	
	$('.scroller-1').scrollbar();
	$('.scroller-2').scrollbar();
	$('.scroller-3').scrollbar();
	
	$(window).resize(function() {
		if (!pageOpen) 
			$('#page-bio, #page-music, #page-erotica, #page-modelling, #page-videos, #page-press, #page-contact, #page-imprint').css({'top': '-100%'});
	});
	
	Cufon.replace('#items a, #attachment a', {
	hover: true
	});
	Cufon.replace('h1, h2, #attachment');
	
	// open page
	$(".open-bio").click(function() { functionOpen("bio"); });
	$(".open-music").click(function() { functionOpenMusic("music"); });
	$(".open-erotica").click(function() { functionOpen("erotica"); });
	$(".open-modelling").click(function() { functionOpen("modelling"); });
	$(".open-videos").click(function() { functionOpen("videos"); });
	$(".open-press").click(function() { functionOpen("press"); });
	$(".open-contact").click(function() { functionOpen("contact"); });
	$(".open-imprint").click(function() { functionOpen("imprint"); });
	
	
	// close page
	$(".close-bio").click(function() { functionClose("bio"); });
	$(".close-music").click(function() { functionCloseMusic("music"); });
	$(".close-erotica").click(function() { functionClose("erotica"); });
	$(".close-modelling").click(function() { functionClose("modelling"); });
	$(".close-videos").click(function() { functionClose("videos"); });
	$(".close-press").click(function() { functionClose("press"); });
	$(".close-contact").click(function() { functionClose("contact"); });
	$(".close-imprint").click(function() { functionClose("imprint"); });

});

function changeTitle(title) { document.title = title; }

function functionClose(k)
{
	var $page = $("#page-" + k);
	$page.animate({top: parseInt($page.css('top'),10) == 0 ? -$page.outerHeight() : 0});
	  
	var $menu = $("#menu");
	$menu.delay(600).animate({top: parseInt($menu.css('top'),10) == 0 ? -$menu.outerHeight() : 0});
		  
	var $player = $("div.jp-audio");
	$player.delay(600).animate({bottom: parseInt($player.css('bottom'),10) == 0 ? -$player.outerHeight() : 0});
	  
	pageOpen = false;
	
	changeTitle("ARESTIRADO | HOME");
}

function functionOpen(k)
{
	var $page = $("#page-" + k);
	$page.delay(600).animate({top: [ parseInt($page.css('top'),10) == 0 ? -$page.outerHeight() : 0, 'easeOutCirc' ]});
	
	var $menu = $("#menu");
	$menu.animate({top: [ parseInt($menu.css('top'),10) == 0 ? -$menu.outerHeight() : 0, 'easeOutCirc' ]});
	
	var $player = $("div.jp-audio");
	$player.animate({bottom: parseInt($player.css('bottom'),10) == 0 ? -$player.outerHeight() : 0});
	
	pageOpen = true;
	
	changeTitle("ARESTIRADO | "+k.toUpperCase());
}


function functionOpenMusic(k)
{
	
	var $page = $("#page-" + k);
	$page.delay(600).animate({top: [ parseInt($page.css('top'),10) == 0 ? -$page.outerHeight() : 0, 'easeOutCirc' ]});
	
	var $menu = $("#menu");
	$menu.animate({top: [ parseInt($menu.css('top'),10) == 0 ? -$menu.outerHeight() : 0, 'easeOutCirc' ]});
	
	var $player = $("div.jp-audio");
	$player.animate({bottom: parseInt($player.css('bottom'),10) == 0 ? -$player.outerHeight() : 0});
	
	$player.css({ position: "relative" });
	$player.css({ padding: 0});	
	$player.css({'padding-bottom': 60});
	$player.css({'margin-top': -37});
	
	var $big1 = $("div.jp-playlist");
	$big1.css({ display: "block" });
	
	var $big2 = $("div.jp-audio div.jp-type-playlist div.jp-current-time");
	$big2.css({ display: "block" });
	
	var $big3 = $("div.jp-audio div.jp-type-playlist div.jp-duration");
	$big3.css({ display: "block" });
	
	pageOpen = true;
	
	changeTitle("ARESTIRADO | "+k.toUpperCase());
		
}


function functionCloseMusic(k)
{
	
	var $big1 = $("div.jp-playlist");
	$big1.css({ display: "none" });
	
	var $big2 = $("div.jp-audio div.jp-type-playlist div.jp-current-time");
	$big2.css({ display: "none" });
	
	var $big3 = $("div.jp-audio div.jp-type-playlist div.jp-duration");
	$big3.css({ display: "none" });
	
	
	var $player = $("div.jp-audio");

	
	$player.css({ position: "fixed" });
	$player.css({ padding: 20});
	
	
	$player.delay(600).animate({bottom: parseInt($player.css('bottom'),10) == 0 ? -$player.outerHeight() : 0});
	
	
	var $page = $("#page-" + k);
	$page.animate({top: parseInt($page.css('top'),10) == 0 ? -$page.outerHeight() : 0});
	  
	var $menu = $("#menu");
	$menu.delay(600).animate({top: parseInt($menu.css('top'),10) == 0 ? -$menu.outerHeight() : 0});
	  
	pageOpen = false;
	
	changeTitle("ARESTIRADO | HOME");
}



