$(function() {
	
	// Setup the Share button ---------------------
	$('.share').hover(function(){
		var theID = $(this).attr("id"); theID = theID.substring(6); // this removes 'share_' and leaves id number
		$('#sharewindow_'+theID).css('display','block'); return false; 
	});
	
		$('.sharewindow').hover(
      function (){
				var theID = $(this).attr("id"); theID = theID.substring(12); // this removes 'sharewindow_' and leaves id number
				$('#share_'+theID).css('background-position','-127px -38px'); 
			},
      function (){ 
				$(this).css('display','none');
				$('.share').css('background-position','-127px 0');
			}
    );
	
	$('.sharewindow').click(function(){ $(this).css('display','none'); });
	
	// setup forms with jqueryFormField ---------------------
	$('.jqueryformfield').val(''); // clears any stored values if used previously
	$('.jqueryformfield').example(function() {
	 	return $(this).attr('title'); // uses the info in the title to display label inside the form field
	});
	
	// Setup the Signup button ---------------------
	$("#signup_submit").click(function() {
	// validate and process form here
	var theName = $("input#signup_name").val();
	var theEmail = $("input#signup_email").val();
	//alert(theName+" "+theEmail);
	if (theName == "" || theName == $("input#signup_name").attr('title') || theEmail == "" || theEmail == $("input#signup_email").attr('title') ){return false;}
	
/*	$('#signup_wrapper').html("<div id='signup_message' style='height:"+$("#signup_wrapper").css('height')+"'></div>");
	$('#signup_message').html("<br/><h3>Subscribing: Please Wait</h3>")*/
	
	return true;
		
		//var theDataString = 'name='+ theName + '&email=' + theEmail;
/*		var theDataString = 'cm-name='+ theName + '&cm-uysuh-uysuh=' + theEmail;
		var theAction = $("#signup_form").attr('action'); //retrieves the value of the action attribute of the form*/
		
/*		$.ajax({
      type: "POST",
      url: theAction,  
      data: theDataString,
      success: function() {
        $('#signup_wrapper').html("<div id='signup_message' style='height:"+$("#signup_wrapper").css('height')+"'></div>");
        $('#signup_message').html("<br/><h3>Thanks for Signing Up!</h3>")
        .hide()
        .fadeIn(1500, function() {
          $('#signup_message');
        });
      }
    });*/
		
		
	});
		
});


// ------------------------------------------------------------------------------

/*
 * jQuery Example Plugin 1.3.4
 * Populate form inputs with example text that disappears on focus.
 *
 * e.g.
 *  $('input#name').example('Bob Smith');
 *  $('input[@title]').example(function() {
 *    return $(this).attr('title');
 *  });
 *  $('textarea#message').example('Type your message here', {
 *    class_name: 'example_text',
 *    hide_label: true
 *  });
 *
 * Copyright (c) Paul Mucur (http://mucur.name), 2007-2008.
 * Dual-licensed under the BSD (BSD-LICENSE.txt) and GPL (GPL-LICENSE.txt)
 * licenses.
 *
 */
(function(A){A.fn.example=function(D,C){var B=A.extend({},A.fn.example.defaults,C,{example_text:D});var E=A.isFunction(B.example_text);if(!A.fn.example.bound_class_names[B.class_name]){A(window).unload(function(){A("."+B.class_name).val("")});A("form").submit(function(){A(this).find("."+B.class_name).val("")});A.fn.example.bound_class_names[B.class_name]=true}return this.each(function(){var G=A(this);var H=A.metadata?A.extend({},B,G.metadata()):B;if(A.browser.msie&&!G.attr("defaultValue")&&(E?G.val()!="":G.val()==H.example_text)){G.val("")}if(G.val()==""){G.addClass(B.class_name);G.val(E?H.example_text.call(this):H.example_text)}if(B.hide_label){var F=A("label[@for="+G.attr("id")+"]");F.next("br").hide();F.hide()}G.focus(function(){if(A(this).is("."+B.class_name)){A(this).val("");A(this).removeClass(B.class_name)}});G.blur(function(){if(A(this).val()==""){A(this).addClass(B.class_name);A(this).val(E?H.example_text.call(this):H.example_text)}})})};A.fn.example.defaults={example_text:"",class_name:"example",hide_label:false};A.fn.example.bound_class_names=[]})(jQuery);

/*
 * Metadata - jQuery plugin for parsing metadata from elements
 *
 * Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id: jquery.metadata.js 3620 2007-10-10 20:55:38Z pmclanahan $
 *
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(9($){$.r({3:{7:{8:\'l\',h:\'3\',q:/({.*})/,4:\'3\'},w:9(a,b){g.7.8=a;g.7.h=b},j:9(b,c){5 d=$.r({},g.7,c);2(!d.4.o)d.4=\'3\';5 a=$.n(b,d.4);2(a)6 a;a="{}";2(d.8=="l"){5 m=d.q.v(b.u);2(m)a=m[1]}k 2(d.8=="t"){2(!b.i)6;5 e=b.i(d.h);2(e.o)a=$.s(e[0].C)}k 2(b.p!=A){5 f=b.p(d.h);2(f)a=f}2(a.z(\'{\')<0)a="{"+a+"}";a=y("("+a+")");$.n(b,d.4,a);6 a}}});$.x.3=9(a){6 $.3.j(g[0],a)}})(B);',39,39,'||if|metadata|single|var|return|defaults|type|function|||||||this|name|getElementsByTagName|get|else|class||data|length|getAttribute|cre|extend|trim|elem|className|exec|setType|fn|eval|indexOf|undefined|jQuery|innerHTML'.split('|'),0,{}))


// --------------------------------------------------------------------
// Make a Comment

function MakeAComment(theCommand,theSiteUrl,thePostID){
	if(theCommand == "start"){
		var theHtml = '<div id="makecomment"><a href="#" onclick="MakeAComment(\'close\'); return false;"><div class="blackout"></div></a><div class="inner"><h2>Make a Comment</h2><form id="commentform" method="post" action="'+theSiteUrl+'/wp-comments-post.php"><input id="makecomment_name" name="author" class="jqueryformfield" type="text" title="Name" /><input id="makecomment_email" name="email" class="textfield_right jqueryformfield" type="text" title="Email (will be kept private)" /><div class="clear"></div><textarea id="makecomment_comment" name="comment" class="jqueryformfield" cols="" rows="" title="Comment">Comment..</textarea><input type="hidden" name="comment_post_ID" value="'+thePostID+'" id="comment_post_ID" /><a href="#" onclick="MakeAComment(\'submit\'); return false;"><div class="enter">Enter</div></a></form><a href="#" onclick="MakeAComment(\'close\'); return false;"><div class="close">close</div></a></div></div>';
		$("#wrapper").append(theHtml);
		// setup forms with jqueryFormField
		$('.jqueryformfield').val(''); // clears any stored values if used previously
		$('.jqueryformfield').example(function() {
			return $(this).attr('title'); // uses the info in the title to display label inside the form field
		});
	}else if(theCommand == "close"){
		$("#makecomment").remove();
	} else { // submit the comment
		// validate and process form here
		var theName = $("input#makecomment_name").val();
		var theEmail = $("input#makecomment_email").val();
		var theComment = $("textarea#makecomment_comment").val();
		if (theName == "" || theName == $("input#makecomment_name").attr('title') || theEmail == "" || theEmail == $("input#makecomment_email").attr('title') || theComment == "" || theComment == $("textarea#makecomment_comment").attr('title') ){ 
			alert("Please fill in all fields"); return false;
		}
		if(!ValidateEmail(theEmail)){
			alert("Please check your email address"); return false;
		}
		document.forms["commentform"].submit();
		return true;
	}
}

function ValidateEmail(str) {
		var at="@"; var dot="."; var lat=str.indexOf(at); var lstr=str.length; var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){return false;}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false;}
		if (str.indexOf(at,(lat+1))!=-1){return false;}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false;}
		if (str.indexOf(dot,(lat+2))==-1){return false;}
		if (str.indexOf(" ")!=-1){return false;}
		return true;
}

