function changeImgWidth() {
	
	array1 = new Array();
	nimgs = $("#wrapper div > img").size();
	
	for (i = 0 ; i < nimgs; i ++) {
	
		array1[i] = $("#wrapper div > img:eq("+i+")").width();
		if (array1[i] > 500)
			$("#wrapper div > img:eq("+i+")").width(500);
	}

}

function create_slide(marg, col, vert) {
//	if (mt == null)
		mt = 1;
	
	if (vert == null)
		vert = false;
		
	counta = $("#wrapper > div").size();
	n = 0;

	$("#da").click(function() {
		n ++;
		if (n == counta -col +1) {
			n = 0;
		}
		
		changeHeightBig();
//			alert(2);
		marg = n * 500;
		
//		alert(n);
		$("#wrapper").animate({
			marginLeft: "-" + marg + "px"
		}, 1000, "easeInOutExpo");
		
		curra = mt - 1;
		shown = n + 1;

	});


	$("#d").click(function() {
		n ++;
		if (n == counta -col +1) {
			n = 0;
		}
		slide(marg, vert);
		
		curra = mt - 1;
		shown = n + 1;

		$("#chgNum").text(shown);
	});
	
	$("#dv").click(function() {
		n ++;
		if (n == counta -col +1) {
			n = 0;
		}
//		slide(marg, vert);
		
		curra = mt - 1;
		shown = n + 1;

		$("#chgNum").text(shown);
	});
	
	$("#a").click(function() {
		n --;
		if (n == -1) {
			n = counta -col;
		}
		slide(marg, vert);
	});
	
	if (counta <= col) {
		$("#cLeft img").hide();
		$("#cRight img").hide();
	}
	
	$("#cLeft img").mouseenter(function() {
		$(this).attr("src", "imgs/arrowL2.png");
	}).mouseleave(function() {
		$(this).attr("src", "imgs/arrowL1.png");
	});
	
	$("#cRight img").mouseenter(function() {
		$(this).attr("src", "imgs/arrowR2.png");
	}).mouseleave(function() {
		$(this).attr("src", "imgs/arrowR1.png");
	});
}


function changeHeight(newheight) {
	if (newheight == null)
		newheight = $("#wrapper div:eq("+n+") > img").height() + 20;
	
	if (newheight < 385)
		newheight = 385;
	//	newheight = $("#wrapper div:eq("+n+")").height();
	
//	alert(newheight);
	
//	alert($("#wrapper div:eq("+n+") > *").height());
	
	$("#mediaDiv, #mediaDiv #cMain, #mediaDivContent").animate({
		height: newheight + "px"
	}, 1000, "easeInOutExpo");

}

function changeHeightBig(newheight) {
	if (newheight == null)
		newheight = $("#wrapper div:eq("+n+") > img").height() + 20;

	newWidth = $("#wrapper div:eq("+n+") > img").width();
//	alert(newheight);
//	if (newheight < 385)
//		newheight = 385;
	//	newheight = $("#wrapper div:eq("+n+")").height();
	
//	alert(newheight);
	
//	alert($("#wrapper div:eq("+n+") > *").height());
	
	$("#bigDiv, #bigDiv #cMain, #mediaDivContent").animate({
		height: newheight + "px"
	}, 1000, "easeInOutExpo");
	$("#cMain").animate({
		width: newWidth + "px"
	}, 1000, "easeInOutExpo");
}

function slide(marg, vert) {

	if (vert)
		changeHeight();
			
	marg = n * marg;
	
	$("#wrapper").animate({
		marginLeft: "-" + marg + "px"
	}, 1000, "easeInOutExpo");

}

function changeImg() {
	$('<div id="imgTempDiv"><img src="'+$("#imgDiv img").attr("src")+'" /></div>').appendTo('body');

	$("#imgTempDiv").width($("#imgDiv").width());
	$("#imgTempDiv").height($("#imgDiv").height());
	$("#imgTempDiv img").width($("#imgDiv img").width());
	$("#imgTempDiv img").height($("#imgDiv img").height());
	$("#imgTempDiv").show();
	
	if (showImg == showMax)
		showImg = -1;
	showImg ++;

	$("#imgDiv img").attr("src", arrayImg[showImg]);
	resizeImg();
	
//	$("#imgTempDiv").effect("fade", {}, 1000, function() {
	$("#imgTempDiv").fadeOut(1500, function() {
		$(this).remove();
	});
	
	setTimeout("changeImg()", 4000);
}

function resizeImg() {
	$("#imgDiv").height($(window).height() - 50);

	imgWidth = $("#imgDiv img").width();
	imgHeight = $("#imgDiv img").height();

	divWidth = $("#imgDiv").width();
	divHeight = $("#imgDiv").height();
	
	imgProp = imgWidth / imgHeight;
	divProp = divWidth / divHeight;

	if (divProp >= imgProp) {
		$("#imgDiv img").width(divWidth);
		$("#imgDiv img").height("");
	} else {
		$("#imgDiv img").width("");
		$("#imgDiv img").height(divHeight);
	}

}

function showMenu() {
	
	$("#topDiv").mouseenter(function() {
		$(this).stop();
		if ($(this).height() != 80) {
			$(this).animate({
				height: "80px"
			}, 500, function() {
				$("#menuDiv ul").show();
				$("#langDiv").show();
			});
		}
	});
	
	$("#loadDiv, #imgDiv, #headerDiv").mouseenter(function() {
		$("#topDiv").stop();
		$("#menuDiv ul").hide();
		$("#langDiv").hide();
		$("#topDiv").animate({
			height: "50px"
		}, 500);
	});
}
