$(function(){

	$('#keywords').focus(function(){
		if ($(this).val() == "SEARCH HE SAID"){$(this).val('');}
	});
	
	$('#keywords').blur(function(){
		if ($(this).val() == ""){
			$(this).val('SEARCH HE SAID');
		}
	});
	

	$("form#footer-form, #sign-up-box form").submit(function(){
	        var inputs = [];
    		$(':input', this).each(function() {
    		    if($(this).is(":checked") || $(this).attr("type") == "text" || $(this).attr("type") == "hidden"){
	           	 	inputs.push(this.name + '=' + escape(this.value));
    			}
        	});
          		
          	var img = new Image();
					
			$(img).attr({
				src: "http://app.bronto.com/public/?q=landingpage&" + inputs.join('&'),
				width: 0,
				height: 0,
				border: 0
			});
			
			$(img).appendTo(document.body);
			
			$(this).fadeOut().replaceWith('<ul><li>Thank You for Subscribing<br /> to He Said.<br /><br />  You will receive a <br />confirmation email shortly.</li></ul>').fadeIn();

		return false;
	});

	/* SET UP BOXY */
	$(".boxy").boxy({
		afterShow: function() {
			this.getContent().css();
			this.center();

			$("form").submit(function(){
				Boxy.get(this).hide();
				
	            var inputs = [];
    		    $(':input', this).each(function() {
    		    	if($(this).is(":checked") || $(this).attr("type") == "text" || $(this).attr("type") == "hidden"){
	           		 	inputs.push(this.name + '=' + escape(this.value));
    				}
          		});
          		
          		if($(this).attr("id") == "bronto-signup")
          		{
          			var img = new Image();
					
					$(img).attr({
						src: "http://app.bronto.com/public/?q=landingpage&" + inputs.join('&'),
						width: 0,
						height: 0,
						border: 0
					}).appendTo(document.body);
					
          		}else{
          			jQuery.ajax({
          				type: "POST",
        	  			data: inputs.join('&'),
    	      			url: this.action
	          		});
          		}

				return false;
			});
			
			$('#invite-friends-link').click(function(){
				var url		= $(this).attr('href');
				var title	= $(this).attr('title');
				
				Boxy.load(url, {'title':title, 'closeable':true, 'closeText': '[close]', 'draggable': true, 'afterShow': function(){
					$("form").submit(function(){
						Boxy.get(this).hide();
				
	           			var inputs = [];
    				    $(':input', this).each(function() {
         		  		 	inputs.push(this.name + '=' + escape(this.value));
         		 		});
          		
         		 		jQuery.ajax({
         		 			type: "POST",
          					data: inputs.join('&'),
          					url: this.action
        		  		});

						return false;
					});
				}});
				
				return false; 
			});
			
		}
	});
	
	/* PRINT PAGE */
	$('#print-page').click(function(){window.print(); return false;});
	
	/* ADD TO FAVORITES */
	$('#save-page').jFav();
	
	/* VIDEOS */
	$('.hs-video').click(function(){
	
		var video = $(this).attr("rel");
		
		var so = new SWFObject("/assets/flash/player.swf?colorInput=0051E3&amp;videoInput="+video, "mymovie", "405", "300", "8", "#FFFFFF");
		
		so.addParam("wmode", "transparent");
		so.write("video");

		return false;
	});
	
	/* FORUM LOOP */
	if ($("#hesaid-forum").length > 0){
		
		var control = $('#more-forum-titles').attr("rel").split('-');
		
		var items	= control[0];
		
		var current	= control[1];
		
		var total = $('#hesaid-forum li').length;

		$('#less-forum-titles').hide();
		
		if (total <= items){$('#more-forum-titles').hide();}

		$('#hesaid-forum li').hide();

		$('#hesaid-forum li').each(function(i){
			if (i <= (items - 1)){$(this).show();}
		});
	}
	
	$('#more-forum-titles').click(function(){

		var control 	= $('#more-forum-titles').attr("rel").split('-');
		
		var items		= parseInt(control[0]);
		
		var current		= parseInt(control[1]);
		
		var next		= current + items;
		var previous	= current;
		
		var total 		= $('#hesaid-forum li').length;
		
		if (next >= (total - items)){$('#more-forum-titles').hide();}else{$('#more-forum-titles').show();}
		
		if (previous < 0){$('#less-forum-titles').hide();}else{$('#less-forum-titles').show();}
		
		$('#hesaid-forum li').each(function(i){
		
			if (i <= (current + items - 1)){$(this).hide();}else if(i > (current + items - 1) && i <= (current + items + items -1)){$(this).show();}

			$('#more-forum-titles').attr("rel", items + '-' + next);
			
			$('#less-forum-titles').attr("rel", items + '-' + previous);

		});		
		
		return false;
		
	});
	
	$('#less-forum-titles').click(function(){

		var control 	= $('#less-forum-titles').attr("rel").split('-');
		
		var items		= parseInt(control[0]); // 2
		
		var current		= parseInt(control[1]); // 0
		
		var next		= current + items;
		
		var previous	= (current - items >- 0) ? current - items : 0;
		
		var total 		= $('#hesaid-forum li').length;
			
		if (current <= 0){$('#less-forum-titles').hide();}else{$('#less-forum-titles').show();}
		
		if (next <= total - 1){$('#more-forum-titles').show();}else{$('#more-forum-titles').hide();}
		
		
		$('#hesaid-forum li').each(function(i){
		
			if (i >= next){$(this).hide();}else if(i >= current && i <= next - 1 ){$(this).show();}else

			$('#more-forum-titles').attr("rel", items + '-' + current);

			$('#less-forum-titles').attr("rel", items + '-' + previous);
		});		
		
		return false;
		
	});	
	
});

function closePopup() {
	Boxy.hideAndUnload();
	return false;
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}