/**
 *
 * MapLayout is (c) 2007 CleoGraphics and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
 $(function(){
	
	var motion_speed = 650;
	var queue_status = false;
	var panelMinHeight = "39px";
	var panelReelHeightold = $("#wpanel").height() +"px";

	$("#maplik_up").click(function(){
		
		//alert($(".map-container").height());
		
		panelReelHeightold = $("#wpanel").height() +"px";
	
		$("#wpanel").height($("#wpanel").height()).removeClass("heightauto");
		$(".map-container").animate({height: "675"},{queue:queue_status, duration:motion_speed});
		
		$("#wpanel").animate({height: panelMinHeight },{queue:queue_status, duration:motion_speed});
		
		setTimeout(function() {
			
			$("#map").animate({width: "762", height: "496", left: "0", marginRight: "0"},{queue:queue_status, duration:motion_speed});
			$("#centermap").animate({width: "716", height: "454"},{queue:queue_status, duration:motion_speed});
			$("#layers").animate({width: "752", left: "0", marginRight: "0"},{queue:queue_status, duration:motion_speed});
			$(".inputlist").animate({ width: "640"},{queue:queue_status, duration:motion_speed});	
			
			$("#topbar").animate({ width: "762"},{queue:queue_status, duration:motion_speed});
			$("#rightbar").animate({ height: "496"},{queue:queue_status, duration:motion_speed});
			$("#bottombar").animate({ width: "762"},{queue:queue_status, duration:motion_speed});
			$("#leftbar").animate({ height: "496"},{queue:queue_status, duration:motion_speed});
			
			$(".toparrow").animate({ left: "349"},{queue:queue_status, duration:motion_speed});
			$(".rightarrow").animate({ top: "234"},{queue:queue_status, duration:motion_speed});
			$(".bottomarrow").animate({ left: "349"},{queue:queue_status, duration:motion_speed});
			$(".leftarrow").animate({ top: "234"},{queue:queue_status, duration:motion_speed});
			
		}, motion_speed);
		
		
		$("#maplik_down").css("display","block");
		$("#maplik_up").css("display","none");
	
	});

	$("#maplik_down").click(function(){
		
		containerReelHeightold = 507;
		//alert(containerReelHeightold);
		panelReelHeightold = parseInt(panelReelHeightold.slice(0, -2));
		//alert(panelReelHeightold);

		if (panelReelHeightold < 390){
			panelReelHeightold = containerReelHeightold
			}
		
		//alert(panelReelHeightold);
		
		$(".map-container").animate({height: panelReelHeightold +5},{queue:queue_status, duration:motion_speed});
		
		$("#map").animate({ width: "502",height: "326",left: "260",marginRight: "261"},{queue:queue_status, duration:motion_speed});	
		$("#centermap").animate({width: "456", height: "284"},{queue:queue_status, duration:motion_speed});
		$("#layers").animate({ width: "492",left: "260",marginRight: "261"},{queue:queue_status, duration:motion_speed});		
		$(".inputlist").animate({ width: "385"},{queue:queue_status, duration:motion_speed});	

		$("#topbar").animate({ width: "502"},{queue:queue_status, duration:motion_speed});
		$("#rightbar").animate({ height: "326"},{queue:queue_status, duration:motion_speed});
		$("#bottombar").animate({ width: "502"},{queue:queue_status, duration:motion_speed});
		$("#leftbar").animate({ height: "326"},{queue:queue_status, duration:motion_speed});
		
		$(".toparrow").animate({ left: "237"},{queue:queue_status, duration:motion_speed});
		$(".rightarrow").animate({ top: "149"},{queue:queue_status, duration:motion_speed});
		$(".bottomarrow").animate({ left: "237"},{queue:queue_status, duration:motion_speed});
		$(".leftarrow").animate({ top: "149"},{queue:queue_status, duration:motion_speed});
			
		setTimeout(function() {
			
			$("#wpanel").animate({ height: panelReelHeightold}, { queue:queue_status, duration:motion_speed });
			
		}, motion_speed);
		
		setTimeout(function() {
			
			$("#wpanel").addClass("heightauto");
			//alert($("#wpanel").css("height"));

		},motion_speed*2);
		
		$("#maplik_down").css("display","none");
		$("#maplik_up").css("display","block");
		
	});	
		
	$('.imgcontainer').draggable({
		cursor: 'http://www.google.com/intl/tr_ALL/mapfiles/closehand.cur'
	});
	
	$('.slider').draggable({
		cursor: 'http://www.google.com/intl/tr_ALL/mapfiles/closehand.cur',
		grid:	[7,8],
		axis:	'vertically',
		containment : 'parent',
		stop: function(){
			slideHeight= 144;
			MapMinHeight= 1014;
			NowTopPoint = parseInt($('.slider').css('top').slice(0, -2));
			NowStep = (slideHeight - NowTopPoint) / 8;
			NowTopPoint = MapMinHeight + (NowStep * 100);
			$('.imgcontainer img').css('width',NowTopPoint);
		}
		
	});
	
	$('.imgcontainer img').mousedown(function(){
		$(this).css({ cursor: "url(http://www.google.com/intl/tr_ALL/mapfiles/closedhand.cur), default"});
	});
	
	$('.imgcontainer img').mouseup(function(){
		$(this).css({ cursor: "url(http://www.google.com/intl/tr_ALL/mapfiles/openhand.cur), default"});
	});
	
	autocontrol_speed = 400;
	step = 200;
	
	$('#map .rightarrow').click(function(){						  
		Nowleft = parseInt($('.imgcontainer').css('left').slice(0, -2)) -  step ;
		$(".imgcontainer").animate({ left: Nowleft},{queue:queue_status, duration:autocontrol_speed});
		return false;
	});
	$('#map .leftarrow').click(function(){						  
		Nowleft = parseInt($('.imgcontainer').css('left').slice(0, -2)) +  step ;
		$(".imgcontainer").animate({ left: Nowleft},{queue:queue_status, duration:autocontrol_speed});
		return false;
	});
	
	$('#map .toparrow').click(function(){						  
		Nowtop = parseInt($('.imgcontainer').css('top').slice(0, -2)) +  step ;
		$(".imgcontainer").animate({ top: Nowtop},{queue:queue_status, duration:autocontrol_speed});
		return false;
	});
	$('#map .bottomarrow').click(function(){						  
		Nowtop = parseInt($('.imgcontainer').css('top').slice(0, -2)) -  step ;
		$(".imgcontainer").animate({ top: Nowtop},{queue:queue_status, duration:autocontrol_speed});
		return false;
	});	
	
	$('#topbar .cornerleft').click(function(){		
		Nowtop = parseInt($('.imgcontainer').css('top').slice(0, -2)) +  step ;
		Nowleft = parseInt($('.imgcontainer').css('left').slice(0, -2)) +  step ;
		$(".imgcontainer").animate({ top: Nowtop, left: Nowleft},{queue:queue_status, duration:autocontrol_speed});
		return false;
	});		
	
	$('#topbar .cornerright').click(function(){		
		Nowtop = parseInt($('.imgcontainer').css('top').slice(0, -2)) +  step ;
		Nowleft = parseInt($('.imgcontainer').css('left').slice(0, -2)) -  step ;
		$(".imgcontainer").animate({ top: Nowtop, left: Nowleft},{queue:queue_status, duration:autocontrol_speed});
		return false;
	});		
	
	$('#bottombar .cornerleft').click(function(){		
		Nowtop = parseInt($('.imgcontainer').css('top').slice(0, -2)) -  step ;
		Nowleft = parseInt($('.imgcontainer').css('left').slice(0, -2)) +  step ;
		$(".imgcontainer").animate({ top: Nowtop, left: Nowleft},{queue:queue_status, duration:autocontrol_speed});
		return false;
	});		
	
	$('#bottombar .cornerright').click(function(){		
		Nowtop = parseInt($('.imgcontainer').css('top').slice(0, -2)) -  step ;
		Nowleft = parseInt($('.imgcontainer').css('left').slice(0, -2)) -  step ;
		$(".imgcontainer").animate({ top: Nowtop, left: Nowleft},{queue:queue_status, duration:autocontrol_speed});
		return false;
	});		
	
	$('#pointListComboBtn').click(function(){
		var listAction = $(".pointlist").css("display") == "block" ? true : false;
		if (!listAction){
			pointListtop = parseInt($('.imgcontainer').css('top').slice(0, -2)) -  step ;
			pointListleft = parseInt($('.imgcontainer').css('left').slice(0, -2)) -  step ;
			$(".pointlist").css("display","block");
			$(".pointlist").css("top","263px");
			if ($.browser.msie){
			   $(".pointlist").css("top","270px");
			}
		} else {
			$(".pointlist").css("display","none");
		}
		return false;
	});	
	
	$('#pluspoint').click(function(){
		var pluspointAction = $(".pointSearch").css("display") == "block" ? true : false;
		if (!pluspointAction){
			$(".pointSearch").css("display","block");
		} else {
			$(".pointSearch").css("display","none");
		}
		
		if ($(".map-container").height() < $("#wpanel").height()){$(".map-container").height($("#wpanel").height()+5)}
		
		
		
		return false;
		
	});
	
	
	$('#pointAddBtn').click(function(){
		$(".betweenContainer").css("display","block");
		$("#betweenpointItem").clone().appendTo('.itemContainer');
		if ($(".map-container").height() < $("#wpanel").height()){
			$(".map-container").height($("#wpanel").height()+10)
		}
		
		$(".removeitem").click(function(){
			$(this).parent().remove();
			return false;
		});
		
		$(".removeitem").mouseover(function(){$(this).addClass("removeitemover");});
		$(".removeitem").mouseout(function(){$(this).removeClass("removeitemover");});
		
		$(".upposition").mouseover(function(){$(this).addClass("avtiveover");});
		$(".upposition").mouseout(function(){$(this).removeClass("avtiveover");});
		
		$(".downposition ").mouseover(function(){$(this).addClass("avtiveover");});
		$(".downposition ").mouseout(function(){$(this).removeClass("avtiveover");});
		
		return false;
	});
	
	
	$('#rotafind').click(function(){
		$("#rotaform").css("display","block");
	});
	
	
	
});
	
