/**
	Name: change-social-newwork-links.js
	Purpose: Change the 'href' attribute of the anchors to be the expected values with encoded url and title.
*/

function changeSocialLinks(_href, _title) {
	try {
		var pageUrl = encodeURIComponent(_href);
		var pageTitle = encodeURIComponent(_title);
		document.getElementById('fbLink').href = "http://www.facebook.com/sharer.php?u=" + pageUrl + "&t=" + pageTitle;
		document.getElementById('stLink').href = "http://www.stumbleupon.com/submit?url=" + pageUrl + "&title=" + pageTitle;
		document.getElementById('twLink').href = "http://twitter.com/home?status=" + pageTitle + encodeURIComponent(' ') + pageUrl;
	} catch (e) {
	}
}

$(document).ready(function(){
						   		   
	//When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').click(function() {
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size
				
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) });
		
		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		//var popMargTop = ($('#' + popID).height() + 80) / 2;
		//var popMargLeft = ($('#' + popID).width() + 80) / 2;
		var popMargTop = ($('#' + popID).height()) / 2;
		var popMargLeft = ($('#' + popID).width()) / 2;
		
		//Apply Margin to Popup
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=65)'}).fadeIn(); //Fade in the fade layer 

		return false;
	});
	
	$('body').append('<div id="popup1" class="popup_block"></div>');
	$('.popup_block').append('<div id="sitemap-r1-c1"><a class="close-and-go" href="#" goto="/index.html"><img src="/images/sitemap/sitemap-off_r1_c1.jpg" /></a></div>');
	$('.popup_block').append('<div id="sitemap-r1-c2"><a class="close-and-go" href="#" goto="/summer-kitchen-all-natural-products-store-locator.html"><img src="/images/sitemap/sitemap-off_r1_c2.jpg" /></a></div>');
	$('.popup_block').append('<div id="sitemap-r1-c3"><a class="close-and-go" href="#" goto="/summer-kitchen-all-natural-products.html"><img src="/images/sitemap/sitemap-off_r1_c3.jpg" /></a></div>');
	$('.popup_block').append('<div id="sitemap-r1-c4"><a class="close-and-go" href="#" goto="/summer-kitchen-all-natural-recipes.html"><img src="/images/sitemap/sitemap-off_r1_c4.jpg" /></a></div>');
	$('.popup_block').append('<div id="sitemap-r2-c1"><a class="close-and-go" href="#" goto="/summer-kitchen-all-natural-spices-and-rubs.html"><img src="/images/sitemap/sitemap-off_r2_c1.jpg" /></a></div>');
	$('.popup_block').append('<div id="sitemap-r2-c2"><a class="close-and-go" href="#" goto="/summer-kitchen-all-natural-condiments.html"><img src="/images/sitemap/sitemap-off_r2_c2.jpg" /></a></div>');
	$('.popup_block').append('<div id="sitemap-r2-c3"><a class="close-and-go" href="#" goto="/summer-kitchen-all-natural-marinades-and-dressings.html"><img src="/images/sitemap/sitemap-off_r2_c3.jpg" /></a></div>');
	$('.popup_block').append('<div id="sitemap-r2-c4"><a class="close-and-go" href="#" goto="/summer-kitchen-all-natural-sauces.html"><img src="/images/sitemap/sitemap-off_r2_c4.jpg" /></a></div>');
	$('.popup_block').append('<div id="sitemap-r3-c1"><a class="close-and-go" href="#" goto="/summer-kitchen-all-natural-seasonal-preserves.html"><img src="/images/sitemap/sitemap-off_r3_c1.jpg" /></a></div>');
	$('.popup_block').append('<div id="sitemap-r3-c2"><a class="close-and-go" href="#" goto="/summer-kitchen-all-natural-products-contact.html"><img src="/images/sitemap/sitemap-off_r3_c2.jpg" /></a></div>');
	$('.popup_block').append('<div id="sitemap-r3-c3"><a href="#" class="close"><img src="/images/sitemap/sitemap-off_r3_c3.jpg" /></a></div>');

	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
	  	$('#fade , .popup_block').fadeOut(function() {
			$('#fade').remove();  
		}); 
		
		return false;
	});
	$('a.close-and-go').live('click', function() { //When clicking on the close or fade layer...
	  	$('#fade , .popup_block').fadeOut(function() {
			$('#fade').remove();  
		}); 
		setTimeout("window.location = \"" + $(this).attr('goto') + "\";",350);
		return false;
	});

});


