

function jqPngFix() {
    try {
        //ie6 png transperency fix
        $.each($("img[src$=.png],img[src$=.PNG]"), function () {
            var img = $(this);
            img.css({"width": img.width(),"height": img.height(), "filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.attr("src") + "', sizingMethod='scale')"});
            img.attr("src","assets/images/construct/blank.gif");
        });
    } catch(e) {
        alert(e.description)
    }
}


printLink = function() {
	if (document.getElementById("printLink")) {
		var printBut = document.getElementById("printLink");
		printBut.onclick=function() {
			if (window.print) {
				window.print();
			} else {
				alert("Unfortunately your browser doesn't support printing via this link.\nTo print this page please select \"File > Print...\" in your browser's menu.");
			}
			return false;
		}
	}
}

addBookmark = function() {
	if (document.getElementById("bookmarkLink")) {
		var bookBut = document.getElementById("bookmarkLink");
		bookBut.onclick=function() {
			if (document.all) {
				bookmarkurl=document.location;
				bookmarktitle="Freedom Financial Solutions";
				window.external.AddFavorite(bookmarkurl,bookmarktitle);
			} else {
				alert("Unfortunately your browser doesn't support adding bookmarks via this link.\n\nTo bookmark this page please use your browser's menu.");
			}
			return false;
		}
	}
}

$(document).ready(function(){
	if ($.browser.msie && $.browser.version == '6.0') {
		jqPngFix();
	}
	
	$('form.hideLabels label').hide();
	$('form.hideLabels input[type="text"]').each(function() {
		$(this).attr('value',$(this).prev().html());
	});
	$('form.hideLabels textarea').each(function() {
		$(this).html($(this).prev().html());
	});
	$('form.hideLabels input[type="text"]').bind({
		focus: function() {
			$(this).fadeTo('fast',1);
			if ($(this).attr("value") == $(this).prev().html()) {
				$(this).attr("value","");
			}
		},
		blur: function() {
			$(this).fadeTo('fast',0.5);
			if (!$(this).attr("value")) {
				$(this).attr("value",$(this).prev().html());
			}
		}
	});
	$('form.hideLabels select').each(function() {
		$thisLabel = $(this).prev().html();
		if ($(this).children('option:eq(0)').attr('value') == "") {
			$(this).children('option:eq(0)').html($thisLabel);
		}
	});
	$('form.hideLabels textarea').bind({
		focus: function() {
			$(this).fadeTo('fast',1);
			if ($(this).html() == $(this).prev().html()) {
				$(this).html(null);
			}
		},
		blur: function() {
			$(this).fadeTo('fast',0.5);
			if ($(this).val() == "") {
				$(this).html($(this).prev().html());
			}
		}
	});
	
	
	$('.formRow input[type="text"], .formRow textarea').fadeTo('fast',0.5);
	$('.formRow input[type="text"]').bind({
		focus: function() {
			$(this).fadeTo('fast',1);
		},
		blur: function() {
			$(this).fadeTo('fast',0.5);
		}
	});
	$('.formRow textarea').bind({
		focus: function() {
			$(this).fadeTo('fast',1);
		},
		blur: function() {
			$(this).fadeTo('fast',0.5);
		}
	});
	$('input[type="submit"]').each(function() {
		$(this).replaceWith('<p class="cta submit"><a href="#">'+$(this).attr('value')+'</a></p>');
	});
	$('p.cta.submit a').click(function() {
		$(this).parents('form').submit();
		return false;
	});
	$('.standfirst p:first, .standfirst .panel p:first-child').addClass('standfirst');
	$('.hero .cta a, .cta.quote a').wrapInner('<span />');
	$(window).scroll(function() {
    	$('.panel.fixed').css({
	    		top: $(this).scrollTop() + "px",
	    		position:"absolute"
    		}
    	);
	});
	
	printLink();
	addBookmark();
});
