// JavaScript Document

$(document).ready(function() {
 	
	$('#mapframe').center();
	
	jQuery.preloadImages = function(){
	  for(var i = 0; i<arguments.length; i++){
		jQuery("<img>").attr("src", arguments[i]);
	  }
	}
	
	MM_preloadImages("img/roundcorners_over/topright1.jpg", "img/roundcorners_over/topleft1.jpg", "img/roundcorners_over/topleft2.jpg", "img/roundcorners_over/topright2.jpg", "img/roundcorners_over/bottomleft2.jpg", "img/roundcorners_over/bottomright2.jpg", "img/roundcorners_over/bottomright1.jpg", "img/roundcorners_over/bottomleft1.jpg", "img/roundcorners/topright1.jpg", "img/roundcorners/topleft1.jpg", "img/roundcorners/topleft2.jpg", "img/roundcorners/topright2.jpg", "img/roundcorners/bottomleft2.jpg", "img/roundcorners/bottomright2.jpg", "img/roundcorners/bottomright1.jpg", "img/roundcorners/bottomleft1.jpg", "img/roundmasks/topright1.gif", "img/roundmasks/topleft1.gif", "img/roundmasks/topleft2.gif", "img/roundmasks/topright2.gif", "img/roundmasks/bottomleft2.gif", "img/roundmasks/bottomright2.gif", "img/roundmasks/bottomright1.gif", "img/roundmasks/bottomleft1.gif")
	
	
	//-----------------------------------------------------------------
	// DEAL WITH THE MAIN MENU
	//
	
   $('.submenu').each(function(){
		if(!$(this).find('.activeitem').length) $(this).hide()
	});
   
   $('.menu-item').click(function(){
   		if(!$(this).parent().find('.submenu').is(':hidden')){
			$(this).parent().find('.submenu').hide("fast")
		}else{
			$('.submenu').hide("fast")
			$(this).parent().find('.submenu').toggle("fast")
		}
  	});
	
	
	$('.separator').html('<img src="img/menudottedline.jpg" width="150" height="1" class="dotted-separator" />');
	
	
	$('.menu-item').each(function(){
		var t = $(this).text();
		
		if($(this).hasClass('activeitem')){
			$(this).html('<img src="menuItemImage.php?state=off&active=1&t=' + t + '" border="0"  />')
			MM_preloadImages('menuItemImage.php?state=on&active=1&t=' + t, 'menuItemImage.php?state=off&active=1&t=' + t)
		}else{
			$(this).html('<img src="menuItemImage.php?state=off&t=' + t + '" border="0"  />')
			MM_preloadImages('menuItemImage.php?state=on&t=' + t, 'menuItemImage.php?state=off&t=' + t)
		}
		
		
	});
	
	
	$('.menu-subitem').each(function(){
		var t = $(this).text();
		
		
		if($(this).hasClass('activeitem')){
			$(this).html('<img src="menuItemImage.php?state=off&active=1&indent=14&fontsize=9&t=' + t + '" border="0"  />')
			MM_preloadImages('menuItemImage.php?state=on&active=1&indent=14&fontsize=9&t=' + t, 'menuItemImage.php?state=off&active=1&indent=14&fontsize=9&t=' + t)
		}else{
			$(this).html('<img src="menuItemImage.php?state=off&indent=14&fontsize=9&t=' + t + '" border="0"  />')
			MM_preloadImages('menuItemImage.php?state=on&indent=14&fontsize=9&t=' + t, 'menuItemImage.php?state=off&indent=14&fontsize=9&t=' + t)
		}
		
		
	});
	
	
	$(".menu-item, .menu-subitem").hover(
		 function()
		 {
		   $(this).find("img").attr('src', $(this).find("img").attr('src').replace("state=off","state=on"))
		 },
		 function()
		 {
		   $(this).find("img").attr('src', $(this).find("img").attr('src').replace("state=on","state=off"))
		 }
	);
	
	//-----------------------------------------------------------------
	// DEAL WITH ROUNDED CORNERS
	//
	
	$('.rounded').each(function(){

		var t = $(this).html();

		$(this).html('<table border="0" cellpadding="0" cellspacing="0" style="background-color:#e7dcaf" class="roundtable"><tr><td colspan="3" align="left"><img class="roundcorner" src="img/roundcorners/topright1.jpg" width="9" height="3" align="right" /><img class="roundcorner" src="img/roundcorners/topleft1.jpg" width="9" height="3" /></td></tr><tr><td align="left" valign="top"><img class="roundcorner" src="img/roundcorners/topleft2.jpg" width="3" height="6" /></td><td rowspan="2" class="roundcontent"></td><td align="right" valign="top"><img class="roundcorner" src="img/roundcorners/topright2.jpg" width="3" height="6" /></td></tr><tr><td align="left" valign="bottom"><img class="roundcorner" src="img/roundcorners/bottomleft2.jpg" width="3" height="6" /></td><td align="right" valign="bottom"><img class="roundcorner" src="img/roundcorners/bottomright2.jpg" width="3" height="6" /></td></tr><tr><td colspan="3" align="left"><img class="roundcorner" src="img/roundcorners/bottomright1.jpg" alt="" width="9" height="3" align="right" /><img class="roundcorner" src="img/roundcorners/bottomleft1.jpg" width="9" height="3" /></td></tr></table>');

		$(this).find('.roundcontent').html(t);
		
	});
	
	$('.rounded').mouseover(function(){
		$(this).find('.roundcorner').each(function(){
			$(this).attr('src', $(this).attr('src').replace("roundcorners","roundcorners_over"))
		});
		
		$(this).find('.roundtable').css('background-color', '#7ba8d1')
	});
	
	$('.rounded').mouseout(function(){
		$(this).find('.roundcorner').each(function(){
			$(this).attr('src', $(this).attr('src').replace("roundcorners_over","roundcorners"))
		});
		
		$(this).find('.roundtable').css('background-color', '#e7dcaf')
	});
	
	$('.roundedinput').each(function(){

		var t = $(this).html();

		$(this).html('<table border="0" cellpadding="0" cellspacing="0" style="background-color:#e7dcaf" class="roundtable" width="97%"><tr><td colspan="3" align="left"><img class="roundcorner" src="img/roundmasks/topright1.gif" width="9" height="3" align="right" /><img class="roundcorner" src="img/roundmasks/topleft1.gif" width="9" height="3" /></td></tr><tr><td align="left"  width="3" valign="top"><img class="roundcorner" src="img/roundmasks/topleft2.gif" width="3" height="6" /></td><td rowspan="2" align="center" class="roundcontent"></td><td align="right" valign="top"  width="3" ><img class="roundcorner" src="img/roundmasks/topright2.gif" width="3" height="6" /></td></tr><tr><td align="left" valign="bottom"><img class="roundcorner" src="img/roundmasks/bottomleft2.gif" width="3" height="6" /></td><td align="right" valign="bottom"><img class="roundcorner" src="img/roundmasks/bottomright2.gif" width="3" height="6" /></td></tr><tr><td colspan="3" align="left"><img class="roundcorner" src="img/roundmasks/bottomright1.gif" alt="" width="9" height="3" align="right" /><img class="roundcorner" src="img/roundmasks/bottomleft1.gif" width="9" height="3" /></td></tr></table>');

		$(this).find('.roundcontent').html(t);
		
		$('.roundtable').find('input,textarea,select').focus(function(){
			$(this).parent().parent().parent().parent().css('background-color', '#7ba8d1')
		});
		
		$('.roundtable').find('input,textarea,select').blur(function(){
			$(this).parent().parent().parent().parent().css('background-color', '#e7dcaf')
		});
		
	});
	
	$('.roundedinputs').each(function(){

		var t = $(this).html(); 

		$(this).html('<table border="0" cellpadding="0" cellspacing="0" style="background-color:#eee" class="roundtable" width="100%"><tr><td colspan="3" align="left"><img class="roundcorner" src="img/roundmasks/topright1.gif" width="9" height="3" align="right" /><img class="roundcorner" src="img/roundmasks/topleft1.gif" width="9" height="3" /></td></tr><tr><td align="left"  width="3" valign="top"><img class="roundcorner" src="img/roundmasks/topleft2.gif" width="3" height="6" /></td><td rowspan="2" align="center" class="roundcontent"></td><td align="right" valign="top"  width="3" ><img class="roundcorner" src="img/roundmasks/topright2.gif" width="3" height="6" /></td></tr><tr><td align="left" valign="bottom"><img class="roundcorner" src="img/roundmasks/bottomleft2.gif" width="3" height="6" /></td><td align="right" valign="bottom"><img class="roundcorner" src="img/roundmasks/bottomright2.gif" width="3" height="6" /></td></tr><tr><td colspan="3" align="left"><img class="roundcorner" src="img/roundmasks/bottomright1.gif" alt="" width="9" height="3" align="right" /><img class="roundcorner" src="img/roundmasks/bottomleft1.gif" width="9" height="3" /></td></tr></table>');

		$(this).find('.roundcontent').html(t);
		
		$('.roundtable').find('input,textarea,select').focus(function(){
			$(this).parent().css('background-color', '#29437b')
			$(this).parent().css('color', '#fff')
		});
		
		$('.roundtable').find('input,textarea,select').blur(function(){
			$(this).parent().css('background-color', '#eee')
			$(this).parent().css('color', '#000')
		});
		
		$('.statespecs').find('input,textarea,select').focus(function(){
			$(this).parent().parent().css('background-color', '#29437b')
			$(this).parent().parent().css('color', '#fff')
		});
		
		$('.statespecs').find('input,textarea,select').blur(function(){
			$(this).parent().parent().css('background-color', '#eee')
			$(this).parent().parent().css('color', '#000')
		});
		
		
	});
	
	
	
	
	//-----------------------------------------------------------------
	// DEAL WITH PROJECT THUMBS AND THEIR BEHAIVIOUR
	//
	$('.projectthumb').click(function(){
		$('.projectimg').attr('src', $(this).attr('src').replace("w=140&h=105","w=311&h=233"))
	});
	
});

function showMap(id){
	$('#mapframe').center();
	$('#mapframe').show()
	var ifrm = $('#mapframe').find('iframe')
	ifrm.attr('src', ifrm.attr('src') + '&id=' + id)
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

