$(document).ready(function(){


// LEFT MENU AND PORTAL LEFT MENU LEFT MENU AND PORTAL LEFT MENU LEFT MENU AND PORTAL LEFT MENU

	$("#wLeftMenu a").mouseover(function(){
		$("#tooltip").html($(this).attr("rel"));
		$("#tooltip").css("display","block");
	});
	$("#wLeftMenu a").mouseout(function(){
		$("#tooltip").css("display","none");
	});


// HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER HEADER 
	$('#Loginusername').css('font-style', 'italic');
	$('#Loginusername').css('color', '#999');
	$('#Loginpassword').css('color', '#999');

	$('#Loginusername').click(function(event) {
		$('#Loginusername').css('font-style', 'normal');
		$('#Loginusername').attr("value","");
		$('#Loginpassword').attr("value","");
		$('#Loginusername').css('color', '#000');
	});
	$('#Loginpassword').click(function(event) {
		$('#Loginpassword').css('font-style', 'normal');
		$('#Loginpassword').attr("value","");
		$('#Loginpassword').css('color', '#000');
	});
	$("#Loginsubmit").click(function(event) {
		if(($('#Loginpassword').attr("value")=="" && $('#Loginusername').attr("value")=="") || $('#Loginusername').attr("value")=="username/mobile" || $('#Loginpassword').attr("value")=="password/pin") {
			alert('Please fill the first box with your username or mobile number, then fill the second box with your password or PIN (if you already have one - else, leave it blank)');
			return false;
		}
		else {
			return true;
		}
	});

//-TABLES TABLES TABLES TABLES

	$('#searchTown input').keyup(function(event) {
		if ((event.keyCode > 65 && event.keyCode < 90) || event.keyCode == 8 ||  event.keyCode == 46) {
			$.get("getTowns.asp", { name: $('#searchTown input').attr("value") },
				function(data) {
					$("#searchTownArea").html(data);
				}
			);	
		}

	});
	
		$('#searchMeteogram input').keyup(function(event) {
		if ((event.keyCode > 65 && event.keyCode < 90) || event.keyCode == 8 ||  event.keyCode == 46) {
			$.get("getMeteograms.asp", { name: $('#searchMeteogram input').attr("value") },
				function(data) {
					$("#searchMeteogramArea").html(data);
				}
			);	
		}

	});
	

	//Get the height of the first item
	$('#mask').css({'height':$('#panel-1').height()});	
	
	//Calculate the total width - sum of all sub-panels width
	//Width is generated according to the width of #mask * total of sub-panels
	$('#panel').width(parseInt($('#mask').width() * $('#panel div').length));
	
	//Set the sub-panel width according to the #mask width (width of #mask and sub-panel must be same)
	$('#panel div').width($('#mask').width());
	
	//Get all the links with rel as panel
	$('a[rel=panel]').click(function () {
	
		//Get the height of the sub-panel
		var panelheight = $($(this).attr('href')).height();
		
		//Set class for the selected item
		$('a[rel=panel]').removeClass('selected');
		$(this).addClass('selected');
		
		//Resize the height
		$('#mask').animate({'height':panelheight},{queue:false, duration:700});			
		
		//Scroll to the correct panel, the panel id is grabbed from the href attribute of the anchor
		$('#mask').scrollTo($(this).attr('href'), 800);		
		
		//Discard the link default behavior
		return false;
	});

//-IMAGES IMAGES IMAGES IMAGES IMAGES 
/*
$("#nav2Days a").mouseover(function(){
	$("#selectDay").html($(this).attr("title"));
	$("#selectDay").css("display","block");
});

$("#navDays a").mouseover(function(){
	$("#selectDay").html($(this).attr("title"));
	$("#selectDay").css("display","block");
});

$("#navDays a").mouseout(function(){
	$("#selectDay").css("display","none");
});

$("#nav2Days a").mouseout(function(){
	$("#selectDay").css("display","none");
});*/


	
//-MAPS MAPS MAPS MAPS MAPS

	$("#icons img").fadeTo("slow", 0.7);
	$("#icons span").hide();

	$("#icons img").mouseover(function(){
		$(this).fadeTo(200, 1);
		$(this).siblings("span").show();
	});
	$("#icons img").mouseout(function(){
		$(this).fadeTo(200, 0.7);
		$(this).siblings("span").hide();
	});
	
	$(".dsable").fadeTo("fast", 0.3);

//-STORMS STORMS STORMS STORMS STORMS 

	$("#Stormicons img").fadeTo("slow", 0.7);
	$("#Stormicons span").hide();

	$("#Stormicons img").mouseover(function(){
		$(this).fadeTo(200, 1);
		$(this).siblings("span").show();
	});
	$("#Stormicons img").mouseout(function(){
		$(this).fadeTo(200, 0.7);
		$(this).siblings("span").hide();
	});
	
//-LIGHTNING LIGHTNING LIGHTNING LIGHTNING LIGHTNING 

	$("#Lightningicons img").fadeTo("slow", 0.7);
	$("#Lightningicons span").hide();

	$("#Lightningicons img").mouseover(function(){
		$(this).fadeTo(200, 1);
		$(this).siblings("span").show();
	});
	$("#Lightningicons img").mouseout(function(){
		$(this).fadeTo(200, 0.7);
		$(this).siblings("span").hide();
	});	
});

function zoomIn(myZoom,myLocation) {
	$('#zoom').attr("value",myZoom);
	$('#location').attr("value",myLocation);
	loadNewMap();
}

function loadNewMap() {
	var myMap;
	
	myMap="images/Trivis/Web2008_HiRes_"+$('#myDay').attr("value")+"_"+$('#mymap').attr("value")+"_"+$('#zoom').attr("value")+"_"+$('#location').attr("value")+".jpg";
	$('#currentMap').attr("src",myMap);
}
