// JavaScript Document
var scrollings = {
	chooseAnimation: function() {
		var check = false; //false if the contact script has not been included yet
		$('.nav').livequery(function(){
			$(this).click(function() {
				var urlToLoad = $(this).attr('href');
				
				if(window.location.hash.substr(1) != urlToLoad.substr(0,urlToLoad.length-5)){
					window.location.hash = urlToLoad.substr(0,urlToLoad.length-5);
					var detailsToSee = urlToLoad + ' #contentBody > *';	
					if ($('#contentBody').is(':hidden')){ 
						scrollings.openingscroll();
						if((urlToLoad === 'contact.html' || urlToLoad === 'guestbook_.php') && !check){
							check = true;
							$.getScript("js/jsbContact.js");	
						}
						$('#contentBody').load(detailsToSee);
					}
					else{ 
						$('#contentBody').animate({height: 0}, 'slow', 'swing', function () {  //alert("sto else");
							$(this).animate({width: 0}, 'slow', 'swing', function(){
								if((urlToLoad === 'contact.html' || urlToLoad === 'guestbook_.php') && !check){
									check = true;
									$.getScript("js/jsbContact.js");	
								}
								$(this).empty();
								$(this).load(detailsToSee);												  
							}); 
							scrollings.innerscroll("down"); 
						});
					}
					$('.nav').each(function(){
						$(this).removeClass("black");
					});
					if($(this).parents("envelop").length < 1){
						$(this).addClass("black");
					}
                    if($(this).attr("href")== "music.html"){
                        $("#music_nav").addClass("black");
                    }
                    if($(this).attr("href")== "gigs.html"){
                        $("#gigs_nav").addClass("black");
                    }
                    if($(this).attr("href")== "who.html"){
                        $("#who_nav").addClass("black");
                    }
                    if($(this).attr("href")== "guestbook_.php" ){
                        $("#guests_nav").addClass("black");
                    }
					return false;
				}
				else{
					return false;
				}
			}); 
		});
	},
	openingscroll: function() { 
		
		$('#header').animate({paddingLeft: 30}, 'slow', 'swing');
		$('#main').animate({paddingLeft: 0}, 'slow', 'swing', function() {
			$('#orizNavButtonPhotos').fadeIn("fast", function() { 
				$('#orizNavButtonMusic').fadeIn("fast", function() { 
					$('#orizNavButtonNews').fadeIn("fast", function() { 
						$('#orizNavButtonVideos').fadeIn("fast", function() {
							$('#orizNavButtonPosters').fadeIn("fast", function() {
								$('#orizNavButtonPerc').fadeIn("fast");
							});
						});
					});
				});
			});
			$('#curl').fadeIn('slow', function() {
				scrollings.innerscroll("down");  
			});
		});
	},
	innerscroll: function(direction) {
		if (direction === "up") {
			$('#contentBody').find('#flashObj').hide('fast',function() {
				$('#contentBody').animate({height: 0}, 'slow', 'swing', function () { 
					$('#circle').fadeIn("fast", function() {
						$('#contentBody').animate({width: 0}, 'slow', 'swing');
					});
				});
			});
		}
		else if (direction === "down") {
			$('#contentBody').animate({width: 560}, 'slow', 'swing', function () { 
				$('#circle').fadeIn("fast", function() {
					$('#contentBody').animate({height: 500}, 'slow', 'swing', function () {
						$('#contentBody').css('height', 'auto');
						$('#contentBody').find('#flashObj').fadeIn();
					});
				});
			});	
		}
		else {
			return false;	
		}
	},
	redirectUrl: function(){
		var hash = window.location.hash.substr(1);
		var check = false;
		$("#contentBody").hide();
		$('.nav').each(function(){
			$(this).removeClass("black");
			var href = $(this).attr('href');
			if(hash === href.substr(0,href.length-5)){
				var toLoad = href+' #contentBody > *';
				$('.nav[href='+href+']').addClass("black");
				$('#contentBody').load(toLoad, '', function () {
					$(this).fadeIn(1000);
					scrollings.openingscroll();
					if((href === 'contact.html' || href === 'guestbook_.php') && !check){
						/*alert("got script");*/
						check = true;
						$.getScript("js/jsbContact.js");	
					}
				});
			}	
		});
	},
	cprLink: function() {
			$('#cpr').click(function() {
			if($(this).children('#cprContent').is(':hidden')) {
				$(this).children('#cprContent').fadeIn('slow');
				$(this).animate({ right: "29px" }, 'slow');
			}
			else {
				$(this).animate({ right: "75px" }, 'slow');
				$(this).children('#cprContent').fadeOut('slow');													 
			}
		});
	},
	init: function() {
		this.chooseAnimation();
		this.redirectUrl();
		this.cprLink();
	}
}
poster = {
	showToGallery: function(){
		$(".posterItem a").livequery(function(){
			$(this).click( function(){
				var photoToShow = $(this).attr('href');	
					$('#bigPoster').fadeOut( "fast", function() {
						$('#bigPoster').html('<img src=\"' + photoToShow + '\" width=\"280\" height=\"396\"  alt=\"\" />' )
							.fadeIn("fast"); 
					});
				return false;
			});
		});
	},
    makeNext: function(){
        $("#arrowNext, #arrowPrev").livequery(function(){
            $(this).click(function(){
                $(".posterItem.pageA").removeClass("pageA").addClass("foo");
                $(".posterItem.pageB").removeClass("pageB").addClass("pageA");
                $(".posterItem.foo").removeClass("foo").addClass("pageB");
            });
        });
    },
    makePrev: function(){
        
    },
	init: function(){
		this.showToGallery();
        this.makeNext();
        this.makePrev();
	}
};

//a function to preload some images
function preloadImages () {
	if (document.images) {
	   	img1 = new Image();
		img2 = new Image();
		img3 = new Image();
		img4 = new Image();
		img5 = new Image();
		img6 = new Image();
		img7 = new Image();
		img8 = new Image();
		img9 = new Image();
		img10 = new Image();
		img11 = new Image();
		img12 = new Image();
		
		img13 = new Image();
		img14 = new Image();
		img15 = new Image();
		img16 = new Image();
		img17 = new Image();
		img18 = new Image();
		img19 = new Image();
		img20 = new Image();
		
		img21 = new Image();
		img22 = new Image();
		img23 = new Image();
		img24 = new Image();
		img25 = new Image();
		img26 = new Image();
		img27 = new Image();
		img28 = new Image();
		img29 = new Image();
		img30 = new Image();
		
		img31 = new Image();
		img32 = new Image();
		img33 = new Image();
		img34 = new Image();
		img35 = new Image();
		img36 = new Image();
		img37 = new Image();
		img38 = new Image();
		img39 = new Image();
		img40 = new Image();

		img41 = new Image();
		img42 = new Image();
		img43 = new Image();
		img44 = new Image();
        img45 = new Image();

        img46 = new Image();
		img47 = new Image();
		img48 = new Image();
		img49 = new Image();
        img50 = new Image();
        img51 = new Image();
		
		img1.src = "images/logo.png";
		img2.src = "images/envelop.jpg";
		img3.src = "images/messageFormBg.jpg";
		img4.src = "images/circles.png";
		img5.src = "images/curl.png";

	   	img6.src = "images/cprBG.jpg";
		img7.src = "images/posters/medium/medium-kuttaro2612.jpg";
		img8.src = "images/posters/medium/medium-beachbar0307.jpg";			   	
		img9.src = "images/posters/medium/medium-brasserie220808.jpg";
	   	img10.src = "images/posters/medium/medium-bullbar280605";

		img11.src = "images/photosObj.png";
		img12.src = "images/photosObj2.jpg";
		
		img13.src = "images/photosObj3.jpg";	
		img14.src = "images/photosObj4.jpg";
		img15.src = "images/photosObj5.jpg";

		img16.src = "images/whoTextBg.jpg";
		img17.src = "images/whereaboutsBg.jpg";
		img18.src = "images/postersBg.jpg";
		
		img19.src = "images/photos/01.jpg";
		img20.src = "images/photos/02.jpg";
		img21.src = "images/photos/03.jpg";
		img22.src = "images/photos/04.jpg";
		img23.src = "images/photos/05.jpg";
		img24.src = "images/photos/06.jpg";
		img25.src = "images/photos/07.jpg";
		img26.src = "images/photos/08.jpg";
		img27.src = "images/photos/09.jpg";
		img28.src = "images/photos/10.jpg";
		img29.src = "images/photos/11.jpg";
		img30.src = "images/photos/12.jpg";
		
		img31.src = "images/posters/small/small-beachbar0307.jpg";			   	
		img32.src = "images/posters/small/small-brasserie220808.jpg";
	   	img33.src = "images/posters/small/small-bullbar280605";
	   	img34.src = "images/posters/small/small-kuttaro2612.jpg";
	   	img35.src = "images/posters/small/small-skala250808.jpg";

		img36.src = "images/posters/small/small-xtreme1305.jpg";
		img37.src = "images/photos/b1.jpg";
		img38.src = "images/photos/b2.jpg";
		img39.src = "images/photos/b3.jpg";
		img40.src = "images/photos/b4.jpg";

        img41.src = "images/photos/b5.jpg";
		img42.src = "images/photos/b6.jpg";
		img43.src = "images/photos/b7.jpg";
		img44.src = "images/photos/b8.jpg";
		img45.src = "images/photos/b9.jpg";

        img46.src = "images/tasteTitle.jpg";
		img47.src = "images/dose8.jpg";
		img48.src = "images/chlup.jpg";
		img49.src = "images/matala.jpg";
        img50.src = "images/justReleased.jpg";
        img51.src = "images/tape.jpg";
	}
};
var gallery = {
	makeGallery: function() {
		$("div.photoItem a").livequery(function(){
			$(this).fancybox({
				'overlayShow': true,
				'frameWidth': 800,
				'frameHeight': 600
			});
		});
	},
	init: function(){
		this.makeGallery();
	}
};


	

//var flashsound ={
//	makesound: function() {
//		$('a[@href$="mp3"]').flash(
//        	{ src: 'singlemp3player.swf', height: 20, width: 100 },
//        	{ version: 7 },
//        	function(htmlOptions) {
//				$this = $(this);
//				htmlOptions.flashvars.file = $this.attr('href');
//				$this.before($.fn.flash.transform(htmlOptions));						
//			}
//		);
//	},
//	init: function () {
//		this.makesound();
//	}
//};



$(document).ready( function(){
	scrollings.init();
	preloadImages();
	poster.init();
	gallery.init();
	$('a[@href$="mp3"]').flash(
        { src: 'singlemp3player.swf', height: 20, width: 100 },
        { version: 7 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.flashvars.file = $this.attr('href');
            $this.before($.fn.flash.transform(htmlOptions));						
        }
    );
});
