var index = window.location.hostname;
var midX, midY, screenW, screenH, current=0;

function screenCenter(){
	midY = $(window).height()/2;
	midX = $(window).width()/2;
}
function alignContent(){
	screenCenter();
	screenW = $(window).width();
	screenH = $(window).height();
	$('body').height(screenH);
	$('body, #header, #footer').width(screenW);
	$('#content-slider').width(5*screenW);
	$('#content-slider, .content-holder, .content').height(screenH-240);
	$('.content-holder').width(screenW);
	$('.scroller').height(screenH-280);
	createSlider('homeScrl', 'homeCnt');
	createSlider('partyScrl', 'partiesCnt');
	createSlider('galleryScrl', 'galleryCnt');
	createSlider('aboutusScrl', 'aboutusCnt');
	createSlider('contactScrl', 'contactCnt');
}
function slideAnim(next){
	amount = -1*(next)*screenW;
	if(next==4){
		initializeMap();
	}
	$('#content-slider').animate({left: amount}, 1000, function() {current = next;});
}
function checkPage(){
	var myFile = document.location.toString();
	if (myFile.match('#')){
		var myAnchor='#'+myFile.split('#')[1];
		next = $('#menu a[href="'+myAnchor+'"]').parent().index();
		if(myAnchor=="#contact"){
			initializeMap();
		}
		slideAnim(next);
	}
}
function createSlider(id,parent){
	$('#'+id).slider('destroy');
	var sliderContent = $('#'+parent+' .scroller .scroller-content');
	sliderContent.css("top","0");
    var amount = parseInt(sliderContent.height())-parseInt($('#'+parent+' .scroller').height());
	if (amount>0){
		var sliderOpts = {  
			max: amount, 
			value: amount,
			slide: function(e, ui){  
         		sliderContent.css("top", "-"+(amount-ui.value)+ "px");  
			},
			orientation:'vertical'
		};  
		$('#'+id).slider(sliderOpts);
		$('#'+id).height($('#'+parent+' .scroller').height()-30);
	}
}
function addNewsletter(){
	if($('#nl-mail').val()!="Enter your e-mail"){
		$.post(index+'?CMD=newsletter', {mail: $('#nl-mail').val()}, function(data){
			if(data){
				$('#newsletter').html(data);	
			}
			else {
				$('#newsletter .error').append('Error! Try again with your real e-mail address!<p>');
			}
		});
	}
	return false;
}

function initializeMap(){
	var latlng = new google.maps.LatLng(45.780955355556685,15.933013558387756);
	var myOptions = {zoom:14,center:latlng,mapTypeId:google.maps.MapTypeId.HYBRID};
	var map = new google.maps.Map(document.getElementById("map"),myOptions);
	var gallery=new google.maps.Marker({position:new google.maps.LatLng(45.780955355556685,15.933013558387756),map:map,title:"Gallery Club Zagreb"});
}

$(function(){
	$('body').css('overflow','hidden');
	$('.content-holder').css('float','left');
	$('.content').css('overflow','hidden');
	$('#content-slider').css('overflow','hidden');
	$('.content h4 a').each(function(){
	    $(this).replaceWith($(this).html());
	});
	
	alignContent();
	checkPage();
	
	$('#menu a').click(function(){
		slideAnim($(this).parent().index());
	});

	$(window).resize(function() {	
		alignContent();
	});
	
	
	$(".fancybox").fancybox({'titleShow':false,'transitionIn':'elastic','transitionOut':'elastic','easingIn':'easeOutBack','easingOut':'easeInBack'});
	$(".fancyboxVid").click(function() {
		$.fancybox({'transitionIn':'elastic','transitionOut':'elastic','easingIn':'easeOutBack','easingOut':'easeInBack','titleShow':false,'width':480,'height':385,'href':this.href.replace(new RegExp("watch\\?v=", "i"),'v/'),'type':'swf','swf':{'wmode':'transparent','allowfullscreen':'true','allowscriptaccess':'always'}});
		return false;
	});
	
	$('#nl-mail').focus(function(){
		if($(this).val()=='Enter your e-mail'){$(this).val('');};
	});
	$('#nl-mail').blur(function(){
		 if($(this).val()==''){$(this).val('Enter your e-mail');};
	});
	$('#nl-submit').click(function(){
		addNewsletter();
	});
});