$(document).ready(function() {
	menu();
	//fotoSlider();
	initSelectboxes();
	albumSlider();
	cycle();
	twitterLink();
});

function cycle(){
	$('#slider_container').cycle({ 
		fx:      'scrollHorz', 
		speed:    500, 
		timeout:  10000,
		next:   '#btn_next', 
		prev:   '#btn_prev'
	});	
}

function twitterLink(){
	$('#twitter a').attr('target','_blank');	
}

function menu() {
	$('.item').hover(function() {
		$(this).children('.submenu').show();						  
	}, function() {
		$(this).children('.submenu').hide();						  
	});
	$('.submenu').hover(function() {
		$(this).parent('.item').find('a.menuitem').css('color','#bd0546');						 
	}, function() {
		$(this).parent('.item').find('a.menuitem').css('color','#00597F');						 
	});
}

var nCurrent = 1;
var nWidth = 722;
var bReady = true;
function fotoSlider() {
	var nTotal = $('#slider_container img').size();

	$('#btn_next').click(function() {
		if(bReady) {
			bReady = false;
			var nCurrentLeft = $('#slider_container').css('left').replace('px','');
			var nLeft = nCurrentLeft - nWidth;
			
			nCurrent++;
			
			if(nCurrent == nTotal) {
				$('#btn_next').hide();
			}
			
			$('#slider_container').animate({
				left: nLeft										
			}, 1000, function() {
				$('#btn_prev').show();
				bReady = true;
			});
		}
	});
	
	$('#btn_prev').click(function() {
		if(bReady) {
			bReady = false;
			var nCurrentLeft = parseInt($('#slider_container').css('left').replace('px',''));
			var nLeft = (nCurrentLeft + nWidth);

			nCurrent--;
			
			if(nCurrent == 1) {
				$('#btn_prev').hide();
			}
			
			$('#slider_container').animate({
				left: nLeft										
			}, 1000, function() {
				$('#btn_next').show();
				bReady = true;
			});
		}
	});
}

function initSelectboxes(){
	$('div.select select').selectbox();
	var zIndex = 9999;
	$('div.form div.entry').each(function(){
		$(this).css('z-index',zIndex);
		zIndex--;
	});
}

var nCurrentAlbum = 4;
var nWidthAlbum = 137;
var bReadyAlbum = true;
function albumSlider() {
	var nTotal = $('#albumcontainer img').size();
	
	if(nTotal > 4) {
		$('#albumnext').show();
	}

	$('#albumnext').click(function() {
		if(bReadyAlbum) {
			bReadyAlbum = false;
			var nCurrentLeft = $('#albumcontainer').css('left').replace('px','');
			var nLeft = nCurrentLeft - nWidthAlbum;
			
			nCurrentAlbum++;
			
			if(nCurrentAlbum == nTotal) {
				$('#albumnext').hide();
			}
			
			$('#albumcontainer').animate({
				left: nLeft										
			}, 400, function() {
				$('#albumprev').show();
				bReadyAlbum = true;
			});
		}
	});
	
	$('#albumprev').click(function() {
		if(bReadyAlbum) {
			bReadyAlbum = false;
			var nCurrentLeft = parseInt($('#albumcontainer').css('left').replace('px',''));
			var nLeft = (nCurrentLeft + nWidthAlbum);

			nCurrentAlbum--;
			
			if(nCurrentAlbum == 4) {
				$('#albumprev').hide();
			}
			
			$('#albumcontainer').animate({
				left: nLeft										
			}, 400, function() {
				$('#albumnext').show();
				bReadyAlbum = true;
			});
		}
	});
}
