$(document).ready(function(){
						   
   //check for external links
   $('a, area').filter(function () {
        return this.hostname && (this.hostname).split(":")[0] !== (location.hostname).split(":")[0] || $(this).attr('rel') == 'external'
    }).not(':has(img, div, mailto)').addClass('external').end().click(function (e) {
        open(this.href);
        e.preventDefault()
    });
		
		$('#popup').hide();
		$('#popup2').hide();
				
	$('.friendMessage').hide();
	
	$('#customer').change(function() {
		$('.memberMessage').toggle();
		$('.friendMessage').toggle();
	});
	
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("fast",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  125);
		$(id).css('left', 300);
	
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});	
	
$("div.background2").css("opacity","0");
$("span#message1").css("opacity","0");
$("span#message2").css("opacity","0");

	  var temp1 = $("span#message1").html();
	  //var temp2 = $("span#message2").html();

	window.setTimeout(function() {
		rotateImages1();
	}, 1);
	
	function rotateImages1() {
		setTimeout(function() {
			  //$("span#message").html(temp1);
			  $("div.background1").animate({ 
				opacity: 0
			  }, 700 );
			  $("div.background2").animate({ 
				opacity: 1
			  }, 700 );
			  rotateImages2();
		}, 6000);
	};
	
	function rotateImages2() {
		setTimeout(function() {
			  //$("span#message").html(temp2);
			  $("div.background2").animate({ 
				opacity: 0
			  }, 700 );
			  $("div.background1").animate({ 
				opacity: 1
			  }, 700 );
			  rotateImages1();
		}, 6000);
	};
	
	/*$("#submit").click(function() {
								
	var dataString = $("select#howHeard").val();
	//alert (dataString);return false;
		
	$.ajax({
      type: "POST",
      url: "/counter.php",
      data: dataString,
      success: function() {
        $('#counterForm').html('<span id="thankYou">Thank you!</span>');
      }
     });
    return false;
	});*/
	
});
