
$(document).ready(function() {

var wrapperWidth = 896;
var bodyWidth = document.body.parentNode.clientWidth;
var wrapperHeight = 740;
var bodyHeight = document.body.parentNode.clientHeight;


var leftPos = parseInt((bodyWidth - wrapperWidth) / 2);
if (leftPos < 1){
	leftPos = 0;
}

var topPos = parseInt((bodyHeight - wrapperHeight) / 2);
if (topPos < 1){
	topPos = 0;
}

$('#wrapper').css('left', leftPos + 'px');
$('#wrapper').css('top', topPos + 'px');


function randomNumber(limit){
  return Math.floor(Math.random()*limit);
}

$(".logos a").each(function() {							  
r = randomNumber($(".logos a").length) -1;
var curLogo = $(".logos a:eq(" + r + ")");
curLogo.remove();
curLogo.appendTo('.logos');
});

var scrollerWidth = 0;
$(".logos a").each(function() {							  
scrollerWidth += parseInt($(this).width());
});
$(".logos").css('width', scrollerWidth + 'px');

startScrolling();

function startScrolling(){
	
var slideSpeed = 40; // pixels per second
var firstLogo = $(".logos a:eq(0)");
var firstLogoWidth = parseInt(firstLogo.width());
var duration = (firstLogoWidth/slideSpeed) * 1000;

$(".logos").animate({left: -firstLogoWidth}, duration, function() {

firstLogo.appendTo('.logos');
$(".logos").css('left','0px');
startScrolling();
});

}

$("#menu > div").hover(function() {
$(this).css('color','#993333');																		
}, function() {
$(this).css('color','#ffffff');	
});

function setSrcoll(sw,sh,iw){
	
//if($(".subHead").css('display') == 'block'){
//$("#scrollblok").css('height','219px');
$("#scrollblok").css('height',sh);
$("#scrollblok").css('width',sw);
$(".index").css('width',iw);


//}else if($("#scrollblok").prev().hasClass('locations')){
//$("#scrollblok").css('height','200px');
//}else{
//$("#scrollblok").css('height','300px');	
//}
var outerdHeight = $("#scrollblok").height();
var innerdHeight = $(".index").height();

var scrollArea = outerdHeight - innerdHeight;
var arrowHeight = $('#up').height();
var butPos = parseInt(outerdHeight - arrowHeight);
//alert(outerdHeight);
//alert(scrollArea);
$('#down').css('top', butPos + 'px');

if(scrollArea < 0)
{
	$("#scrollbar > img").show();
	$("#scrollbar > img").hover(function() {
								var divId = $(this).attr('id');
								animateBlok(divId,scrollArea);
								//alert(scrollArea);
								}, function() {
								$(".index").stop();
								//alert('stopped');
								});
}
else
{
	$("#scrollbar > img").hide();
}

}

function animateBlok(direction,scrollArea)
{
	if (direction == 'down')
	{
		var pos = scrollArea + 'px';

		$(".index").animate({top: pos}, 6000);
	}

	if (direction == 'up')
	{
		$(".index").animate({top: '0px'}, 6000);
	}

}

var bindBehaviors = function() {


if($(".index #gallery").text() == '') {	
	var name = 'mall';
	var pageName = "gallery2.php?o=" + name;
	
	$("#gallery .index").load(pageName, function() {
			setSrcoll('500px','270px','480px');									 
			$('#gallery .index a').lightBox({fixedNavigation:true});										
		});	
};

$(".gallery_head > div").click(function() {	
	var name = $(this).attr('id');
	var pageName = "gallery2.php?o=" + name;
	
	$("#gallery .index").load(pageName, function() {
		setSrcoll('500px','270px','480px');
		$('#gallery .index a').lightBox({fixedNavigation:true});								
		});	
});

if ($("#infomap object").attr('title') == '') {	
	var name = 'punda';
	var pageName = "info.php?o=" + name;
	
	$(".index").load(pageName, function() {
			setSrcoll('360px','200px','330px');
			bindBehaviors();											
		});
	$("object").attr('title',name);
	$("param #movie").attr('value','movies/' + name + '.swf');
	$("embed").attr('src','movies/' + name + '.swf');	
	$("#" + name).addClass('active');

};

$(".locations > div").not('.active').click(function() {	
	$(".active").removeClass();									 
	var name = $(this).attr('id');
	var pageName = "info.php?o=" + name;
	
	$(".index").load(pageName, function() {
			setSrcoll('360px','200px','330px');
			bindBehaviors();											
		});
	$("object").attr('title',name);
	$("param #movie").attr('value','movies/' + name + '.swf');
	$("embed").attr('src','movies/' + name + '.swf');	
	$(this).addClass('active');

});

$(".locations > div").not('.active').hover(function() {
	$(this).addClass('over');
}, function() {
	$(this).removeClass('over');
});


$(".link").click(function() {
	var category = $(this).parent().attr('class') + "s";	
	var name = $(this).parent().attr('id');
	var pageName = category + ".php?o=" + name;	
	$(".index").load(pageName, function() {
			setSrcoll('360px','219px','330px');
			bindBehaviors();											
		});
	$(".subHead img").attr('src','images/' + category + '/' + name + '_icon.png');	
	$(".subHead").show();
	$(".rightBlock div img").attr('src','images/' + category + '/' + name + '.png');
	$(".rightBlock div p").text($("#" + name + " div.name").text());	
	$(".back").click(function() {
						  
		$(".content").load(category + ".html", function() {
			$(".subHead").hide();
			setSrcoll('360px','300px','330px');
			bindBehaviors();											
		});
	})
});


};

$('.content').load('home.html', function() {
bindBehaviors();
});



$("#menu > div").click(function() {
var pageName = $(this).attr('id') + ".html";
$('.content').load(pageName, function() {
setSrcoll('360px','300px','330px');
bindBehaviors();
});
});

});