function getWindowHeight(){
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
        return window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
        return document.body.clientHeight;
    }
    return 0;
}
function getWindowWidth(){
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
        return window.innerWidth;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientWidth;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
        return document.body.clientWidth;
    }
    return 0;
}

$(function(){
	var ajaxImage = "<img id='ajaxIMG' src='/common_images/ajax-loader.gif'/>";
	var ajaxImage2 = "<img id='ajaxIMG' src='/common_images/ajax-loader2.gif'/>";
	var ajaxImageSrc = "/common_images/ajax-loader.gif";

    $('#park_fact_container').each(function() {
		$(this).corner();
		$(this).parent().css('padding', '2px').corner("round 12px");
    });
	$('.rounded_corners').each(function() {
		$(this).corner();
    });
	
	// PICTURES
	
	$(".thumblink").click(function(){
		var arr;
		var src_big=$(this).attr("href");
		var src_featured=$(".featured_src").attr("src");
		var src_thumb=$(this).children().attr("src");
		var title = $(this).attr("title");
		var alt = $(this).children().attr("alt");
		arr=src_thumb.split("/");
		var pic_id=arr[arr.length-1];
		var path=src_featured.substring(0,src_featured.lastIndexOf("/")+1);
		
		$(".featured_src").attr("src",ajaxImageSrc);
		$(".featured_src").attr("src",path+pic_id);
		$(".featured_link").attr("href",src_big);
		$(".featured_link").attr("title", title);
		$(".featured_src").attr("alt", alt);
		return false;
	});
	
	$(".park_pollAjaxForm").ajaxForm({
		beforeSubmit: function(){
			$(".park_pollSubmit").attr("disabled","disabled");
			$(".park_pollSubmit").after(ajaxImage);
		},
		success: function(data, statusText){
			$("#park_poll").html(data);
		},
		url: $("#park_pollAjaxForm").val()
	});
	
	
	// DESCRIPTION
	$("#park_description_more").html('<span class="alleventslink"><img src="/common_images/img/tiny_arrow.gif" alt=" " height="7" width="4"> <a href="" id="alleventslinktext">Read More...</a></span>');
	
	$("#alleventslinktext").toggle(
		function() {
			$("#longparkdescription").show();
			$("#alleventslinktext").text("Close");
		},
		function() {
			$("#longparkdescription").hide();
			$("#alleventslinktext").text("Read more...");
		}
	);
	
	$("#longparkdescription").hide();
	
	// Contacts
	$("#park_contacts_more").html('<span class="alleventslink"><img src="/common_images/img/tiny_arrow.gif" alt=" " height="7" width="4"> <a href="" id="allcontactslinktext">View More...</a></span>');
	
	$("#allcontactslinktext").toggle(
		function() {
			$("#park_contacts_more_div").show();
			$("#allcontactslinktext").text("Close");
		},
		function() {
			$("#park_contacts_more_div").hide();
			$("#allcontactslinktext").text("View more...");
		}
	);
	
	$("#park_contacts_more_div").hide();
	
	// PANORAMA
	$.extend({
		loadPanorama: function(id){
			$.get("/sub_your_park/park_page/ajax_panorama.php", {
				pid: id
			}, function(data){
				$("#park_panorama_image").remove();
				$("#park_panorama_applet_del").remove();
				$("#park_panorama_applet").html(data);
			});
		}
	});
	
	$("#park_panorama_select").change(function(){
		var id = $("#park_panorama_select option:selected").val();
		$.loadPanorama(id);
	});
	
	//INSPECTION:
	$(".inspectiondata").hide();
	$(".inspectionlink").click(function(){
		var id="#tbl_"+$(this).attr("id");
		$(id).toggle();
		return false;
	});
	
	//CAPITAL
	$("#capital_more").html('<a href="" id="allcapitalktext">View More...</a>');
	$(".more_capital").hide();
	$("#capital_more").toggle(
		function() {
			$(".more_capital").show();
			$("#allcapitalktext").text("Less");
		},
		function() {
			$(".more_capital").hide();
			$("#allcapitalktext").text("View more...");
		}
	);
	
	//$("#capprjtbl tr:odd").css("background-color", "#bbbbff");
	
	//MONUMENTS
	$(".monthumblink").click(function(){
			var arr;
			var src_big=$(this).attr("href");
			var src_featured=$(".monfeatured_src").attr("src");
			var src_thumb=$(this).children().attr("src");
			
			arr=src_thumb.split("/");
			var pic_id=arr[arr.length-1];
			var path=src_featured.substring(0,src_featured.lastIndexOf("/")+1);
			
			$(".monfeatured_src").attr("src",path+pic_id);
			$(".monfeatured_link").attr("href",src_big);
			return false;
		});
	//DIRECTIONS
	
	$(".dir_more").each(function(){
		var idArr=this.id.split("__");
		var id=idArr[1];
		$(this).after('<span id="'+id+'" class="dir_more_link"><span class="ellipse">&hellip;</span> <a href="#">More</a></span>');
		$(this).hide();
	});
	$(".dir_more_link a").toggle(function(){
		var sp=$(this).parent();
		var id = sp.attr("id");
		$(this).text("Less");
		$("#dir__"+id).show();
		sp.children(".ellipse").hide();
		return false;
	},
	function(){
		var sp=$(this).parent();
		var id = sp.attr("id");
		$(this).text("More");
		$("#dir__"+id).hide();
		sp.children(".ellipse").show();
		return false;
	});

    // CLOSURES
    $('.closure_image_link').each(function(){
        var height = getWindowHeight();
        var width = getWindowWidth();
        var link = $(this).attr('href');
        if(height < 700){
            height = height - 100;
            if(height < 100)
                height = 100;
            link = link.replace(/570/,height);
        }
        if(width < 850){
            width = width - 50;
            if(width < 100)
                width = 100;
            link = link.replace(/800/,width);
        }

        $(this).attr('href',link);
    });
    $('#view_more_link').text('More Details');
    $('#close_more_div').hide();
    $('#view_more_link').click(function(){
        $(this).remove();
        $('#close_more_div').show();
        return false;
    });
	
	if ($('#park_links_list li').length > 3) {
		$('#park_links_list li:gt(2)').hide();
		$("#park_links_list").after('<span class="alleventslink"><img src="/common_images/img/tiny_arrow.gif" alt=" " height="7" width="4"> <a href="" id="alllinks">View More...</a></span>');
		
		$("#alllinks").toggle(function(){
			$('#park_links_list li:gt(2)').show();
			$("#alllinks").text("Close");
		}, function(){
			$('#park_links_list li:gt(2)').hide();
			$("#alllinks").text("View more...");
		});
	}	
	
	$('.album').toggle(
			function(){
//				$('.album_div').hide();
//				$('.album').text('Show');
				
				var arr= $(this).attr('rel').split('__');
				if ($('#album_div_' + arr[1] + ' table').length > 0) {
					$('#album_div_' + arr[1] + ' table').show();
					$('#album_' + arr[1]).text('Hide');
				}
				else {
					$('#album_div_' + arr[1]).append(ajaxImage2);
					$.get('/sub_your_park/park_page/ParkPageAjax.php?cmd=showAlbum', {
						albumId: arr[1],
						parkId: arr[0]
					}, function(data){
						$('#ajaxIMG').remove();
						$('#album_div_' + arr[1]).append(data);
						$('.fancybox').unbind();
						$('.fancybox').fancybox({titlePosition:'inside'});
						//tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
						$('#album_' + arr[1]).text('Hide');
					}, "html");
				}
				return false;	
			},
			function(){
				var arr= $(this).attr('rel').split('__');
				$('#album_div_'+arr[1]+' table').hide();
				
//				$('.album_div table').hide();
				
				$(this).text('Show');
				return false;
			}
			
			);
});