$(document).ready(function() {
	
	$("ul.pdfs li a").each(
	function () {
		if($(this).attr("title")) {
		var title = $(this).attr("title");
		$(this).parent().append('<div class="tooltip"><h3>'+title+'</h3></div>');
	}
});
$(".tooltip").hide();
$(".tooltip").css("cursor","pointer").click(function () {
		var addr = $(this).parent().children('a').attr("href");
		window.location = addr;
});
$(".tooltip").parent().hover(function () { $(this).children(".tooltip").show(); }, function () { $(this).children(".tooltip").hide(); });
$(".tooltip").hover( function () { $(this).show(); });
$(".tooltip h3").hover( function () { $(this).parent().show(); });

	
	
	//hiding and showing .hidden
	$('.hidden').hide();
	$(".reveal").css({cursor: "pointer"})
	$(".reveal").hover(
		function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		}
	);

	$(".reveal").toggle(function(){
			//$('.hidden').slideUp("fast");
			$(this).addClass("open");
			$(this).next($('.hidden')).slideDown("normal");
		},function(){
			$(this).removeClass("open");
			$(this).next($('.hidden')).slideUp("fast");
	});	

	$('#pollhidden').hide();
	$("#pollreveal").css({cursor: "pointer"})
	$("#pollreveal").hover(
		function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		}
	);

	$("#pollreveal").toggle(function(){
			//$('.hidden').slideUp("fast");
			$(this).addClass("open");
			$('#pollhidden').show("normal");
		},function(){
			$(this).removeClass("open");
			$('#pollhidden').hide("fast");
	});	


	$('.pds-answer').before('<p id="pollrevealer">Vote in this Poll now</p>');
	$('.pds-answer').hide();
	$('.pds-vote').hide();
	$("#pollrevealer").css({cursor: "pointer"})
	$("#pollrevealer").click(function(){
			//$('.hidden').slideUp("fast");
			$(this).hide("normal");
			$('.pds-answer').show("normal");
			$('.pds-vote').show("normal");
	});	

/*
if ($("body.single-about").length > 0){
$("body.single-about tr td:last-child").css({ "width":"25%", "paddingLeft":"5%" });
	
}*/


	$("#loginreveal").toggle(function(){
			$('#loginbox').show("fast");
			return false;
		},function(){
			$('#loginbox').hide("fast");
			return false;
	});	

	$(".showlogin").toggle(function(){
			$('#loginbox').show("fast");
			return false;
		},function(){
			$('#loginbox').hide("fast");
			return false;
	});	

	$(".logintrue").toggle(function(){
			$('html, body').animate({ scrollTop: 0 }, 'slow');
			$('#loginbox').show("fast");
		
		},function(){
			$('#loginbox').hide("fast");
		
	});

if ($("body.single-about #content table").length > 0){
$("body.single-about tr td:last-child").css({ "width":"30%", "paddingLeft":"5%" });
$(".intro").css({ "width":"388px", "paddingRight":"240px" });
	
}

if ($("body.page-cart").length > 0){
$("td.product-name a").click(function(){ return false; });
$("td.product-thumbnail a").click(function(){ return false; });
}

if ($("#reviewdetails").length > 0){

$("#reviewdetails tr td:last-child").css({ "width":"107px" });
 
if ($("#review").length > 0){

$("#reviewdetails").prepend($("#reviewdetails div h3"));
$("#reviewheading").addClass("active");
$('#review').addClass("open");
$("#testresults").hide();
$("#specs").hide();
	
/*	#testresultsheading, #specsheading, #reviewheading
	*/


	$("#reviewheading").click(function(){
		if($(this).hasClass('active')) {
			return false;
		} else {
			$('.open').hide().removeClass("open");
			$('#reviewdetails h3').removeClass("active");
			$(this).addClass("active");
			$('#review').show().addClass("open");
		}
	});	
	$("#testresultsheading").click(function(){
		if($(this).hasClass('active')) {
			return false;
		} else {
			$('.open').hide().removeClass("open");
			$('#reviewdetails h3').removeClass("active");
			$(this).addClass("active");
			$('#testresults').show().addClass("open");
		}
	});
	$("#specsheading").click(function(){
		if($(this).hasClass('active')) {
			return false;
		} else {
			$('.open').hide().removeClass("open");
			$('#reviewdetails h3').removeClass("active");
			$(this).addClass("active");
			$('#specs').show().addClass("open");
		}
	});


} else {

$("#reviewdetails").prepend($("#reviewdetails div h3"));
$("#testresultsheading").addClass("active");
$('#testresults').addClass("open");
$("#specs").hide();
	$("#specsheading").css({"borderRight":"2px solid #FFF"});
/*	#testresultsheading, #specsheading, #reviewheading
	*/

	$("#testresultsheading").click(function(){
		if($(this).hasClass('active')) {
			return false;
		} else {
			$('.open').hide().removeClass("open");
			$('#reviewdetails h3').removeClass("active");
			$(this).addClass("active");
			$('#testresults').show().addClass("open");
		}
	});
	$("#specsheading").click(function(){
		if($(this).hasClass('active')) {
			return false;
		} else {
			$('.open').hide().removeClass("open");
			$('#reviewdetails h3').removeClass("active");
			$(this).addClass("active");
			$('#specs').show().addClass("open");
		}
	});


}


}

if ($("#joinbox").length > 0){

	$('#joinbox *').css("cursor","pointer").click(function () {
		var addr = $("#joinbox").children('h3').children('a').attr("href");
		window.location = addr;
      });
}

if ($("section#sub ul.children").length > 0){
	
	$("section#sub ul.children").hide();
	$("section#sub ul.children").parent().click(function(){
			$(this).children('ul').slideDown("fast");
			if ($(this).hasClass("open")) {
					
			} else {
				$(this).addClass("open");
				$(this).parent().children('ul').slideDown("fast");
				return false;
			}
	});
}


if ($("section#sub ul.accordion").length > 0){
	$("section#sub ul.accordion li ul").hide();
	$("section#sub ul.accordion li span.month").css({display: 'block', cursor: 'pointer'});
	$("section#sub ul.accordion li span.month").click(function(){
			if ($(this).hasClass ("open")) {
				$(this).parent().css({"background":"none"});
				$(this).parent().parent().children().children('ul').slideUp("fast");
				$('.open').removeClass("open");
			} else {
				$(this).parent().parent().children().children('ul').slideUp("fast");
				$(this).parent().css({"background":"none"});
				$(this).parent().children('ul').slideDown("fast");
				$('.open').removeClass("open");
				$(this).addClass("open");	
			}
	});
}

	
	
  

// replaceText
(function($){$.fn.replaceText=function(b,a,c){return this.each(function(){var f=this.firstChild,g,e,d=[];if(f){do{if(f.nodeType===3){g=f.nodeValue;e=g.replace(b,a);if(e!==g){if(!c&&/</.test(e)){$(f).before(e);d.push(f)}else{f.nodeValue=e}}}}while(f=f.nextSibling)}d.length&&$(d).remove()})}})(jQuery);

if ($("#slides").length > 0){
		$(function(){
			// Set starting slide to 1
			var startSlide = 1;
			// Get slide number if it exists
			//if (window.location.hash) {
				//startSlide = window.location.hash.replace('#','');
			//}
			// Initialize Slides
			$('#slides').slides({
				preload: true,
				preloadImage: 'img/loading.gif',
				generatePagination: true,
				play: 6000,
				pause: 1000,
				hoverPause: true,
				// Get the starting slide
				start: startSlide
				//,
				//animationComplete: function(current){
					// Set the slide number as a hash
					//window.location.hash = '#' + current;
				//}
			});
		});
	
	//$(".slideinfo h2 a").replace("’","apos");
	
	$(".slideinfo h2 a").append('<br class="clear" />');
  	$(".slideinfo h2 a").replaceText(/\,/g,'<b class="punc">,<\/b>');
	$(".slideinfo h2 a").replaceText(/\./g,'<b class="punc">.<\/b>');
	$(".slideinfo h2 a").replaceText(/\&/g,'<b>\u0026<\/b>');
	$(".slideinfo h2 a").replaceText(/\–/g,'<b>\u2013<\/b>');
	$(".slideinfo h2 a").replaceText(/\-/g,'<b>\u2013<\/b>');
	$(".slideinfo h2 a").replaceText(/\!/g,'<b class="punc">\!<\/b>');
	$(".slideinfo h2 a").replaceText(/\?/g,'<b class="punc">\?<\/b>');
	$(".slideinfo h2 a").replaceText(/\:/g,'<b class="punc">\:<\/b>');
	$(".slideinfo h2 a").replaceText(/\;/g,'<b class="punc">\;<\/b>');
	//$(".slideinfo h2 a").replaceText(/\&apos;/g,'<b class="punc">\u0027<\/b>');
	$(".slideinfo h2 a").replaceText(/\'/g,'<b class="punc">\u2019<\/b>');
	var test = {};
	function get_word( str ){  return test[ str ]  ? '<b>' + str + '<\/b>'  : '<b>'+str+ '<\/b>'; };
	$(".slideinfo h2 a").replaceText( /\b(\S+)\b/g, get_word );
	// $('.slideinfo h2 a').wrapInner('<span />'); 
	
	
	
	$('.slide img').css("cursor","pointer").click(function () {
		var addr = $(this).parents('.slide').children('.slideinfo').children('h2').children('a').attr("href");
		window.location = addr;
      });

		
};
 

 
	
});

	
	


