$(document).ready(function() {
	/* Modal Functionalities */
	positionModal = function(){
		var wWidth  = window.innerWidth;
		var wHeight = window.innerHeight;

		if (wWidth==undefined) {
			wWidth  = document.documentElement.clientWidth;
			wHeight = document.documentElement.clientHeight;
		}

		var boxLeft = parseInt((wWidth / 2) - ( $("#modal").width() / 2 ));
		var boxTop  = parseInt((wHeight / 2) - ( $("#modal").height() / 2 ));

		// position modal
		$("#modal").css({
			'margin': boxTop + 'px auto 0 ' + boxLeft + 'px'
		});

		// scroll to top
		//$('html').animate({scrollTop: 0 }, 'slow');
	}
	loadModal = function(url, srcIsUrl, addCloseButton){
		$("body").append('<div id="modalBackground" class="fixedTopLeft"></div>');
		$("#modalBackground").css("opacity", "0.6");
		$("body").append('<div id="modalcontainer" class="fixedTopLeft"></div>');
		$("#modalcontainer").css("z-index", "900");
		$("#modalcontainer").append('<div id="modal"></div>');

		$("#modal").hide();
		//$('#modalBackground').bgiframe();
		
		
		if (srcIsUrl) {
			$.ajax({
				type: 'GET',
				url: url,
				dataType:"html",
				data: {},
				success: function(html) {
					$("#modal")
						.html(html)
						.fadeIn('fast');

					if (addCloseButton) {
						$("#modal").append('<a href="#" id="xButton" class="closeModal"><span class="hide">close</span></a>');
					}
					positionModal();
					
				},
				error: function() {
					alert("Error loading page");
					closeModal();
				}
			});
		}
	}
	closeModal = function(){
		$("#modalcontainer").remove();
		$("#modalBackground").remove();
	}
	$(".closeModal").live('click', function(){
		closeModal();
	});
	// initialize the Green Resources links to modal window
	$('#askAQuestion').click(function() {
		loadModal('/GreenResources/modal/askAQuestion.html', true, false);
	});
	// initialize the links to modal window
	$('#contactUs').click(function() {
		loadModal('modal/WIG-Contact.html', true, false);
	});
	/*
	$('#headerContact').click(function() {
		loadModal('modal/WIG-Contact.html', true, false);
	});
	*/
	$('#headerContact').click(function() {
		loadModal($(this).attr("href").toString(), true, false);
		return false;
	});
	$('#marketsServed').click(function() {
		loadModal('modal/WIG-Markets.html', true, false);
	});
	
	$('#marketsServedPVF').click(function() {
		loadModal('modal/WIG-Markets-PVF.html', true, false);
	});
	
	$('#marketsServedINT').click(function() {
		loadModal('modal/WIG-Markets-INT.html', true, false);
	});
	
	$('#marketsServedMRO').click(function() {
		loadModal('modal/WIG-Markets-MRO.html', true, false);
	});

	//WIG: Set the border styles of brands
	$('.special .brands .brand-logo:even').addClass('border-right');
		
	// set opacity to null on page load  
	$("#location-finder-link a span").css("opacity","0"); 
	 
	$("#location-finder-link a span").hover(
		function () {
			// animate opacity to full
			$(this).stop().animate({
				opacity: 1 }, 500);
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).stop().animate({
				opacity: 0 }, 500);
		}
	);
	
	
	// set opacity to null on page load  
	$("#email-signup-link a span").css("opacity","0"); 
	 
	$("#email-signup-link a span").hover(
		function () {
			// animate opacity to full
			$(this).stop().animate({
				opacity: 1 }, 500);
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).stop().animate({
				opacity: 0 }, 500);
		}
	);
	
	// set opacity to null on page load 
	$("#btn_rofessional span").css("opacity","0");
	$("#btn_homeowner span").css("opacity","0");  
	$(".btn-search span").css("opacity","0"); 
	$(".btn-submit span").css("opacity","0");
	
	// on mouse over
	$("#btn_rofessional span").hover(
		function () {
			// animate opacity to fullw
			$(this).stop().animate({
				opacity: 1 }, 500);
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).stop().animate({
				opacity: 0 }, 500);
		}
	);

	$("#btn_homeowner span").hover(
		function () {
			// animate opacity to full
			$(this).stop().animate({
				opacity: 1 }, 500);
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).stop().animate({
				opacity: 0 }, 500);
		}
	); 

	$(".btn-submit span").hover(
		function () {
			// animate opacity to full
			$(this).stop().animate({
				opacity: 1 }, 500);
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).stop().animate({
				opacity: 0 }, 500);
		}
	);
	
	$(".btn-search span").hover(
		function () {
			// animate opacity to full
			$(this).stop().animate({
				opacity: 1 }, 500);
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).stop().animate({
				opacity: 0 }, 500);
		}
	);

}); 


