function checkDefaultValue(inputid,inputval){
    if($('#'+inputid).val() == inputval || $('#'+inputid).val() == ''){
         $('#'+inputid)
         	.val('')
         	.focus()
         	.css({'font-style':'normal'})
         	.css({'color':'#323232'});
         return false;
    }
    return true;
}

function fixLOSHeader(imgNum) {
	var el = 'img[src*="libid='+imgNum+'"]';

	$(el)
		.css({'border':'none'})
		.css({'padding':'12px 0 5px 12px'});
	
	if ($.browser.msie && $.browser.version <= 7) { 
/* 		$(el).css({'padding':'15px 15px 0 15px'}); */
	}
}

function fixLOSContact(imgNum) {
	var el = 'img[src*="libid='+imgNum+'"]';

	$(el)
		.css({'border':'none'})
		.css({'position':'relative'})
		.css({'top':'-6px'}); 
}

function setShadows() {
    if ($(window).width() < 960) {
    	$('#shadow-top, #shadow-left, #shadow-right').hide();	
    } else {
    	$('#shadow-top, #shadow-left, #shadow-right').show();	
    }
};

function fixIE6Submit() {
	if ($.browser.msie && $.browser.version <= 6) { $('#search-submit-button').css({"top":"0"}).css({"right":"0"}); }
	if ($.browser.msie && $.browser.version <= 7) { $('#content.property-assets a:first-child').css({'margin-top':'15px'}); }
}

function martinPlaceFixes() {
	$('table tr:even').addClass("alt");
	if ($('table tr:even').is(".alt")) {
		if ($('table tr:even h3').length > 0 ) {
			$('table tr:even h3').parent().parent().addClass("table-header");
		}
	}
	
	$('dl table tr.table-header:first h3').css({'padding-top':'0px'});
	$('dl table').css({'padding-left':'0'});
	
	$('dl table tr td:first-child').css({'width':'320px'}).css({'padding-right':'0px'});
    $("dl table tr").hover(
      function () {
      	if (!$(this).is('.table-header')) {
	        $(this).css({'background-color':'#323232'}).css({'color':'#fff'});
    	    $('a', this).css({'color':'#fff'});
    	}
      }, 
      function () {
   		$(this).css({'background-color':'#fff'});
        $(this).css({'color':'#787878'});
        $('a', this).css({'color':'#555'});
      }
    );
}

function loadPropertyAssets() {
	$("#content.property-assets a").hover(
	  function () {
	  	oldHeight = $('img', this).attr("height");
	  	newHeight = oldHeight * 1.4;
	  	oldWidth = $('img', this).attr("width");
	  	newWidth = oldWidth * 1.4;
	  	$(this).stop().animate({height:newHeight, width:newWidth}, 100);
	    $('img', this).stop().animate({height:newHeight, width:newWidth}, 200);	
	  },
	  function () {
		  $(this).stop().animate({height:oldHeight, width:oldWidth}, 200);
	    $('img', this).stop().animate({height:oldHeight, width:oldWidth}, 100);	
	  }
	);
}

var resizeTimer = null;
$(window).bind('resize', function() {
    if (resizeTimer) clearTimeout(resizeTimer);
    resizeTimer = setTimeout(setShadows, 100);
});	

$(document).ready(function() {
	//image submit buttons
	$("#search-submit-button").click(function(){ $("#search-submit").trigger("click"); });
	$("#contact-submit-button").click(function(){ $("#contact-submit").trigger("click"); });

	//extend los to full width of container	
	$('#landmarks-of-style a:last-child').css({'width':'190px'});
	
	//textbox highlight
    $('#search input').blur(function(){
		$(this).parent().removeClass("focus");
    })
    .focus(function() {                
    	$(this).parent().addClass("focus")
    });
    
	//textbox highlight
    $('input').blur(function(){
		$(this).removeClass("focus");
    })
    .focus(function() {                
    	$(this).addClass("focus");
    });
 
    //textarea highlight
    $('textarea').blur(function(){
		$(this).removeClass("focus");
    })
    .focus(function() {                
    	$(this).addClass("focus")
    });
	
	//pngfix
	$('#shadow-top, #shadow-left, #shadow-right').pngfix();
	
	//alternating bgs
	$('#news a:odd').addClass('alternate');
	$('#landmarks-of-style a:odd').addClass('alternate');
	
	//fix first image indent (ie6)
	$('#content img:first').parent().addClass('first-child');

	//new window for external links
	$("a[href^='http']").attr('target','_blank');
	$("#slideshow a, a[href*='ipoh']").attr('target','_self');
	
	//remove borders and fix alignment for landmarks of style pages, uses libid of images (for ie6)
	fixLOSContact("251");
	fixLOSContact("252");
	fixLOSContact("253");
	fixLOSHeader("257");
	fixLOSHeader("259");
	fixLOSHeader("260");
	fixLOSHeader("261");
	fixLOSHeader("276");
	fixLOSHeader("292");

	$('img[src*="libid=295"]').wrap('<a href="http://www.qvb.com.au" target="_blank"></a>');
	$('img[src*="libid=296"]').wrap('<a href="http://www.strandarcade.com.au" target="_blank"></a>');
	$('img[src*="libid=297"]').wrap('<a href="http://www.tgv.com.au" target="_blank"></a>');
	$('img[src*="libid=294"]').wrap('<a href="http://www.chifleyplaza.com.au" target="_blank"></a>');


	var oldHeight;
	var newHeight;

	$('#content h2:contains("Property Assets")').parent().addClass('property-assets');
	if ($('#content').is('.property-assets')) { loadPropertyAssets(); }

	setShadows(); //fix shadows on load
	fixIE6Submit(); //move IE6 submit
	if ($.browser.msie && $.browser.version <= 7) { $('h2:contains("Corporate News")').css({'margin-top':'5px'}); }

	//google maps
	var gMaps = new Array();
	var gMapsNum = 0;
	gMaps[0] = '';
	//tgv
	gMaps[1] = '<div id="google-maps"><iframe width="630" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.au/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=500+George+St,+NSW+2000&amp;sll=-33.867788,151.207752&amp;sspn=0.007822,0.010439&amp;ie=UTF8&amp;hq=&amp;hnear=500+George+St,+New+South+Wales+2000&amp;ll=-33.872072,151.208181&amp;spn=0.003563,0.013497&amp;z=16&amp;output=embed&amp;iwloc=near"></iframe><br /><a href="http://maps.google.com.au/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=500+George+St,+NSW+2000&amp;sll=-33.867788,151.207752&amp;sspn=0.007822,0.010439&amp;ie=UTF8&amp;hq=&amp;hnear=500+George+St,+New+South+Wales+2000&amp;ll=-33.872072,151.208181&amp;spn=0.003563,0.013497&amp;z=16" style="text-align:left" target="_blank">+ View Larger Map</a></div>';
	//chifley
	gMaps[2] = '<div id="google-maps"><iframe width="630" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.au/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=2+Chifley+Square&amp;sll=-33.872393,151.207881&amp;sspn=0.007821,0.010439&amp;ie=UTF8&amp;hq=&amp;hnear=2+Chifley+Square,+Sydney+New+South+Wales+2000&amp;ll=-33.865997,151.211572&amp;spn=0.003563,0.013497&amp;z=16&amp;output=embed&amp;iwloc=near"></iframe><br /><a href="http://maps.google.com.au/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=2+Chifley+Square&amp;sll=-33.872393,151.207881&amp;sspn=0.007821,0.010439&amp;ie=UTF8&amp;hq=&amp;hnear=2+Chifley+Square,+Sydney+New+South+Wales+2000&amp;ll=-33.865997,151.211572&amp;spn=0.003563,0.013497&amp;z=16" style="text-align:left" target="_blank">+ View Larger Map</a></div>';
	//strand
	gMaps[3] = '<div id="google-maps"><iframe width="630" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.au/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=193-195+Pitt+Street+Mall&amp;sll=-33.866086,151.211507&amp;sspn=0.007822,0.010439&amp;ie=UTF8&amp;hq=&amp;hnear=193%2F195+Pitt+Street+Mall,+New+South+Wales+2000&amp;ll=-33.869935,151.208611&amp;spn=0.003563,0.013497&amp;z=16&amp;output=embed&amp;iwloc=near"></iframe><br /><a href="http://maps.google.com.au/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=193-195+Pitt+Street+Mall&amp;sll=-33.866086,151.211507&amp;sspn=0.007822,0.010439&amp;ie=UTF8&amp;hq=&amp;hnear=193%2F195+Pitt+Street+Mall,+New+South+Wales+2000&amp;ll=-33.869935,151.208611&amp;spn=0.003563,0.013497&amp;z=16" style="text-align:left" target="_blank">+ View Larger Map</a></div>';
	//qvb
	gMaps[4] = '<div id="google-maps"><iframe width="630" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.au/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=455+George+St,+Sydney+NSW+2000&amp;sll=-33.858135,151.20874&amp;sspn=0.007822,0.010439&amp;ie=UTF8&amp;hq=&amp;hnear=455+George+St,+New+South+Wales+2000&amp;ll=-33.871511,151.206701&amp;spn=0.001782,0.006759&amp;z=17&amp;output=embed&amp;iwloc=near"></iframe><br /><a href="http://maps.google.com.au/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=455+George+St,+Sydney+NSW+2000&amp;sll=-33.858135,151.20874&amp;sspn=0.007822,0.010439&amp;ie=UTF8&amp;hq=&amp;hnear=455+George+St,+New+South+Wales+2000&amp;ll=-33.871511,151.206701&amp;spn=0.001782,0.006759&amp;z=17" style="text-align:left" target="_blank">+ View Larger Map</a></div>';
	//martin place
	gMaps[5] = '<div id="google-maps"><iframe width="630" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.au/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=1+Martin+Place&amp;sll=-33.871012,151.206572&amp;sspn=0.007821,0.010439&amp;ie=UTF8&amp;hq=&amp;hnear=1+Martin+Pl,+Sydney+New+South+Wales+2000&amp;ll=-33.867814,151.208181&amp;spn=0.003563,0.013497&amp;z=16&amp;output=embed&amp;iwloc=near"></iframe><br /><a href="http://maps.google.com.au/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=1+Martin+Place&amp;sll=-33.871012,151.206572&amp;sspn=0.007821,0.010439&amp;ie=UTF8&amp;hq=&amp;hnear=1+Martin+Pl,+Sydney+New+South+Wales+2000&amp;ll=-33.867814,151.208181&amp;spn=0.003563,0.013497&amp;z=16" style="text-align:left" target="_blank">+ View Larger Map</a></div>';

	function setGMapsNum() {
		if ($("#content p:contains('500 George St')").length > 0) { gMapsNum = 1; } //tgv
		if ($("#content p:contains('2 Chifley Square')").length > 0) { gMapsNum = 2; } //chifley plaza
		if ($("#content p:contains('193-195 Pitt Street Mall')").length > 0) { gMapsNum = 3; } //the strand
		if ($("#content p:contains('455 George Street')").length > 0) { gMapsNum = 4; } //qvb
		if ($("#content p:contains('1 Martin Place')").length > 0) { gMapsNum = 5; martinPlaceFixes(); } //no.1 martin place
	}

	$("#content a" ).each(
		function(){
			if ($(this).text() == 'View Map') {
				$(this).attr("id", "map-toggle");
				setGMapsNum();
				$(this).parent().append(gMaps[gMapsNum]);
				$("#google-maps")
					.css({'position':'absolute'})
					.css({'visibility':'hidden'});
				
				$("#map-toggle").click(function(){
					if ($("#google-maps").length > 0) {
						if ($('#map-toggle').html() == 'Hide Map') {
							$('#map-toggle').html('View Map');
							$("#google-maps").stop(true, true).slideUp("slow");
						} else {
							$('#map-toggle').html('Hide Map');
							$("#google-maps")
								.css({'position':'relative'})
								.css({'visibility':'visible'})
								.hide()
								.stop(true, true)
								.slideDown("slow");
						}
					}
					return false;
				});
			}	 
		}
	);
});

