RoundedCornersTR_BL = new Array('page-intro','feature-item-list', 'related-links', 'additional-information', 'feature-item', 'contact-information', 'contact-form'); 
MinusMarginTop = new Array ('section-2-col', 'section-no-col');

$(document).ready(function(){	
	$('a[rel=lightbox]').lightBox(); 
	if (jQuery.browser.msie && jQuery.browser.version <= 6.0) {
		correctPNG();
	}
	if (!jQuery.browser.mozilla && !jQuery.browser.msie) {
		addRoundedCorners(RoundedCornersTR_BL);
	}

	if (jQuery.browser.mozilla && parseFloat(jQuery.browser.version) <= 1.9) {	
	}
	else {
		$('.feature-item-list').css('background-image', 'url("../images/background_blue.jpg")');
		$('.feature-item-list').css('background-repeat', 'repeat-x');
		$('.additional-information').css('background-image', 'url("../images/background_sea_blue.jpg")');
		$('.additional-information').css('background-repeat', 'repeat-x');
	}

	if (jQuery.browser.msie && jQuery.browser.version <= 6.0) {	
	}
	else if (jQuery.browser.opera) {
	}
	else {
		replacementText();
	}
	if ($("#contactForm")) {
		clearDefaultText($('#contactForm'));
		$("#contactForm").validate({
			rules: {field: "required"}
		}); 
	}
	
	if ($("#commentsForm")) {
		clearDefaultText($('#commentsForm'));
		$("#commentsForm").validate({
			field: 'required',
			submitHandler: function(form) {
				$("#commentsForm").ajaxSubmit({
					beforeSubmit:   showRequest,
					success:        function (data) {
						if (data.comment == '') {
							$('#submitting').fadeOut('fast', function () {
								$('#submit-button').fadeIn ('fast');
							});
						}
						else {
							$('<p>').attr('class', 'emphasis').attr('id', 'comment_'+data.comment_id).attr('style', 'display:none;').appendTo('#comments');
							$('#comment_'+data.comment_id).html('<strong>At '+data.date+', '+data.name+' ('+data.email+') said:</strong><br/>'+data.comment+'');
						
							$('#comment_'+data.comment_id).slideDown('fast' ,function(){
								$('#submitting').fadeOut('fast', function () {
									$('#submit-button').fadeIn ('fast');
								});
							});
						}
					},
					url:       	   '/submit_comment',  // override for form's 'action' attribute 
					dataType:      'json',      // 'xml', 'script', or 'json' (expected server response type) 
					resetForm:     true,        // reset the form after successful submit 
					timeout:       3000,
					error: 		   function(){
						$("#response").html("<p>Sorry, an error occured. Please try again later.</p>");
						return false;
					}
				});
			}
		});
	}
});
 
function addRoundedCorners(RoundedCornersTR_BL) {	
		for (var c=0; c<RoundedCornersTR_BL.length; c++) {
			$('.'+RoundedCornersTR_BL[c]).prepend('<span class="roundedCorner roundedCornerTopRight" />');
			$('.'+RoundedCornersTR_BL[c]).append('<span class="roundedCorner roundedCornerBottomLeft"/>');		
		};
		$('.top-nav-list li').each(function() {
			$(this).prepend('<div class="roundedCornerTopRight-nav" /><div class="roundedCornerBottomLeft-nav" />');
		});	
		/*$('.sub-nav-list li').each(function() {
			$(this).prepend('<div class="roundedCornerTopRight-sub-nav" />');
			$(this).append('<div class="roundedCornerBottomLeft-sub-nav" />');
		});	*/
		for (var d=0; d<MinusMarginTop.length; d++) {
			$('.'+MinusMarginTop[d]).css('margin-top', '-1.45em');
			$('.'+MinusMarginTop[d]).css('margin-bottom', '-1.45em');
		}
		$('fieldset').css('margin', '-7px 3px 4px -2px');
}

function replacementText () {
	Cufon.replace('.replacement');
	if (!jQuery.browser.msie) {
		if (!jQuery.browser.safari) {
			$('span.logo-tagline').css('margin-top', '-1.1em');
		}	
	}
	$('span.logo-tagline').css('margin-left', '-5em');
	$('h3').css('letter-spacing', '0.05em;');
}

function clearDefaultText (form) {
	$(':input', form).each( function () { 
		if ($(this).attr('type') != 'submit' && $(this).attr('type') != 'textarea') {
			
			$(this).click(function() { 
				$(this).attr('value', '');
			});
		}
	});
}
	
function showRequest(formData, jqForm) { 
	var queryString = $.param(formData); 
    $('#submit-button').fadeOut ( 'fast', function () {
    	$('<p>').attr('id', 'submitting').attr('class', 'loading').text('submitting ...').appendTo('#submit');
	});
	return true; 
} 

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}


