var isMSIE = /*@cc_on!@*/false,
	originHeighAry = [],
	src = '',
	isModalOpen = false,
	currentArea,
	imgsToLoad = [];
	
	
$(document).ready(function(){
	$('.rollover').rollover();
	
	var navLen = $('#nav_sec>ul>li').length;
	var hasChildLen = $('#nav_sec ul li ul').length;
	var dif = navLen - hasChildLen;
	
	$('#nav_sec ul li ul').each(function(){
		originHeighAry.push($( this).height());
	});
	
	if($('#top_images img').length > 0){
		$('#top_images').cycle({ 
			fx:     'fade', 
			timeout: 4000,
			speed:  1200
		});
	}

	$('.area_map').click(function(){
		openModalWindow($(this).attr('href'));
	})
	
	$('.map_close, #grayLayer, #overLayer').live('click', function(){
		closeModalWindow();
	})	

	$('#nav_sec>ul>li').hover(function(){
			if($('ul', this).length > 0){
				var thisIndex = $(this).index() - dif;
				var originH = $('ul', this).height();
				$('ul', this).css({'height':0, 'width': 194, 'z-index': 9999}).show().stop().animate({'height': originHeighAry[thisIndex]}, 200, 'easeOutQuad');
				$('ul li', this).css({'z-index': 9999});
				el = $('img:first', this).attr('src');
				var imgAry = $('img:first', this).attr('src').split('/');
				var len = imgAry.length;
				var imgName = imgAry[len-1].replace('.', '_on.');
				var imgPath = el.replace(imgAry[len-1],imgName);	
				$('img:first', this).attr('src', imgPath);
			}
		},function(){
			if($('ul', this).length > 0){
				var originH = $('ul', this).height();
				$('img:first', this).attr('src', $('img:first', this).attr('src').replace('_on.', '.'));
				$('ul', this).stop().animate({'height': 0}, 200, 'easeOutQuad', function(){
					$(this).hide();
				});
			}
		})


	var settings = {
		showArrows: false,
		autoReinitialise: true,
		verticalDragMinHeight: 87,
		verticalDragMaxHeight: 87
	};
	
	if($('.skanto .second_sec_box .scroll_content').length > 0){
		$('.skanto .second_sec_box .scroll_content').jScrollPane(settings);
	}
	
	
});

	$(window).bind('resize', function() {
		if (isModalOpen){
			$('#grayLayer').css('height', $(html).height());
		}
	});		

function openModalWindow(target){
		isModalOpen = true;
		currentArea = target;
	
		var scrollPos = getScrollPosition();
		var s = scrollPos.y;
		var h = ($(window).height() / 2) - ($('.areamap').height() / 2);
		var y = s + h;
		
		$("body").append("<div id='grayLayer'></div><div id='overLayer'></div>");
		
		$("#grayLayer").show().css("height", $('html').height()).animate({"opacity": "0.8"}, 200, function(){
			$("#overLayer").show().append($(target));
			$(target).css({'margin-top': y}).show();
		});

		
}

function closeModalWindow(){
		$('#grayLayer, #overLayer').animate({'opacity': 0}, 400, 'easeOutQuint', function(){
			$(currentArea).hide().insertAfter('#wrapper');
			$(this).remove();
			isModalOpen = false;
			currentArea = '';
		 });
}

function getScrollPosition() {
	var obj = new Object();
	obj.x = document.documentElement.scrollLeft || document.body.scrollLeft;
	obj.y = document.documentElement.scrollTop || document.body.scrollTop;
	return obj;
}



