//On load functions
window.onload = function(){
	$("#wrapper").animate({opacity:1},1000);
};
//Variables
var myWidth = 0;
var myHeight = 0;
var boxPos = 0;

//Document ready functions
$(document).ready(function(){
	//Construct functions
    xmlRequest("about.html");
	mainImageRoll();
	setInterval("mainImageRoll()",9000);
	//Box fade 
	boxFade();
	setInterval("boxFade()",5000);
	//Get resolution
	 getResolution();
	//Set vertical margin
	/*if(myHeight > 750) {
		var topMargin = (myHeight-750)/2;
		$("#page").css("marginTop",topMargin);
		$("#bgSlide").css("top",topMargin);
		};*/
	//Language select
	$('select').change(function(){
		if($(this).val() == "en"){
			var url = "en/index.html";    
			$(location).attr('href',url);
			}
		if($(this).val() == "hu"){
			var url = "../index.html";    
			$(location).attr('href',url);
			}	
		});
	
	//Menu links
	$('#menu a,#footer a').click(function (evt){
		 $('#content').html("<div style='text-align:center'><img class='loadimg' src='images/loading.gif'></div>");
        if (evt) {
            var url = evt.target;
        } else {
            var url = window.event.srcElement;
        }
        xmlRequest(url);
        return false;
	});
	//Other links
	$(".boxlink").click(function(){
		url = $(this).attr("href");
		xmlRequest(url);
        return false;	
	});
	

	//Logo effect
	setTimeout("$('#logo').animate({opacity:0.3},1000)",2000);	
	setTimeout("$('#logo').animate({opacity:1},1000)",3000);	
	
	
});

//Functions
function xmlRequest(url){
	$.ajax({
        url: url,
		type: "post",
        success: function (data) {
			$('#content').html(data);
            }
      });
	}	

function getResolution() {
	if (typeof(window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
	if(myWidth < 1300){
		$("#bgSlide img").attr("src", "images/backgroundslide/2.jpg");	
	}	
}

function mainImageRoll() {
	setTimeout(function(){
		$(".mainImage1").animate({opacity:0},1000);
	},3000);
	setTimeout(function(){
		$(".mainImage2").animate({opacity:1},1000);	
	},4000);
	setTimeout(function(){
		$(".mainImage2").animate({opacity:0},1000);	
	},7000);
		setTimeout(function(){
		$(".mainImage1").animate({opacity:1},1000);
	},8000);
}

function boxFade(){
	setTimeout(function(){
		$(".photoSlide a img").eq(boxPos).animate({opacity:0},500);	
	},4000);
	setTimeout(function(){
		if(boxPos == 4){boxPos = -1;}
		$(".photoSlide a img").eq(boxPos+1).animate({opacity:1},500);	
		boxPos++;
	},4500);
}
