//alert('hello world');
$(function(){var debug = false; var ua=navigator.userAgent.toLowerCase();var myBrowsers={mozilla:$.browser.mozilla,safari:$.browser.safari,opera:$.browser.opera,ie:$.browser.msie,ie6:$.browser.msie&&($.browser.version<7),ie7:$.browser.msie&&($.browser.version==7),ie8:$.browser.msie&&($.browser.version>7),iphone:/iphone/.test(ua),chrome:/chrome/.test(ua),firefox:/firefox/.test(ua),webkit:/webkit/.test(ua),osx:/mac os x/.test(ua),win:/win/.test(ua),linux:/linux/.test(ua)};if(debug){i=1;}$.each(myBrowsers,function(a,b){if(b)$('html').addClass(a);if(b&&debug){if(i==1){x='Browser: '}else if(i==2){x='Browser Version: '}else{x='OS: '}alert(x+a);i++;}});});
$(function(){
	var template_url = $('body').attr('rel');
	
	if($('#header li:first').hasClass('current_page_item') || $('#header li:first').hasClass('current_page_parent')){
		$('#header ul li a:first').css({background:'url('+template_url+'/images/rounded_tab.png) #778c61 0 -31px no-repeat'});
	} else {
		$('#header ul li a:first').css({background:'url('+template_url+'/images/rounded_tab.png) #849eaf no-repeat'});
		//Instead of somehow adding a class to the first <a> tag without using a first-child since IE
		//Has issues with it and a :hover psudeo class, we'll use jQuery instead
		$('#header ul li a:first').hover(
			function(){$(this).css({background:'url('+template_url+'/images/rounded_tab.png) #778c61 0 -31px no-repeat'});},
			function(){$(this).css({background:'url('+template_url+'/images/rounded_tab.png) #849eaf no-repeat'});}
		);
	}
	
	
	$('.post_info .comments').each(function(){
		var comment_link = $(this).parent().parent().prev('h1').children('a').attr('href')+'#comment_form';
		$(this).children('a').attr('href',comment_link);
	});
	
	
	/*<![CDATA[*/

	/***********************************************
	* Encrypt Email script- Please keep notice intact
	* Tool URL: http://www.dynamicdrive.com/emailriddler/
	* **********************************************/
	<!-- Encrypted version of: rmickler [at] ********************.*** //-->

	var emailriddlerarray=[114,109,105,99,107,108,101,114,64,109,105,99,107,108,101,114,97,110,100,97,115,115,111,99,105,97,116,101,115,46,99,111,109]
	var encryptedemail_id61='' //variable to contain encrypted email 
	for (var i=0; i<emailriddlerarray.length; i++)
	 encryptedemail_id61+=String.fromCharCode(emailriddlerarray[i])
	$('.contact-container p').append('<a href="mailto:'+encryptedemail_id61+'">&gt;&gt; Click to Send an Email</a>')
	//document.write()
	
	
	if(!$('html').hasClass('ie6')){
		// Let's keep the stylistic HTML stuff out of the normal DOM tree since they serve no purpose other than eye candy
		$('body').prepend('<div id="top-shadow"></div>').append('<div id="bottom-shadow"></div>');
		$('#wrapper').wrap('<div id="shadow-wrapper"></div>');
		$('#home-bottom-wrapper').wrap('<div id="home-bottom-wrapper-shadow"></div>');
		$('#home-bottom-wrapper-shadow').append('<div class="clear"></div>');
		$('#sub-wrapper').wrap('<div id="sub-wrapper-shadow"></div>');
		
		//Keep the more links like text links to text browsers and search engines...	
		$('.more a').each(function(){
			the_href = $(this).attr('href');
			$(this).empty().append('<a href="'+the_href+'"><img src="'+template_url+'/images/more.png" alt="more" /></a>');
		});
		
	}
	
	
	
	
	
	///START IE6 STUFF
	if($('html').hasClass('ie6')){
		
		//Fix <img>s
		var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])
		
		if ((version >= 5.5) && (document.body.filters)) 
		{
		   for(var i=0; i<document.images.length; i++)
		   {
		      var img = document.images[i]
		      var imgName = img.src.toUpperCase()
		      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		      {
		         var imgID = (img.id) ? "id='" + img.id + "' " : ""
		         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		         var imgStyle = "display:inline-block;" + img.style.cssText 
		         if (img.align == "left") imgStyle = "float:left;" + imgStyle
		         if (img.align == "right") imgStyle = "float:right;" + imgStyle
		         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		         var strNewHTML = "<span " + imgID + imgClass + imgTitle
		         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		         img.outerHTML = strNewHTML
		         i = i-1
		      }
		   }
		}
	}
	///END IE6 STUFF
	
	
	$('.comment:even').addClass('even').next().addClass('odd');
	
	$('#blog-feed .article:last').css({paddingBottom:'0'});
	
	
	$('#home-bottom-wrapper > div h2').each(function(){
		var headlineText = $(this).text().split(' ')[0];
		var headlineText2 = $(this).text().split(' ')[1];
		$(this).empty().append(headlineText+'<span style="font-weight:normal;"> '+headlineText2+'</span>');
		
	});
	
	$('#sub-wrapper .left ul.nav:first-child li a').prepend('&gt;&gt; ');
	
	$('#customer-feed a').each(function(){$(this).addClass('del').parent().wrapInner('<a href="'+$(this).attr('href')+'"></a>').find('.del').remove();});
	
	$('#sub-footer li').each(function(){$(this).append(' | ');});
	
	if($('#sub-footer li').length > 0){
		var newLastFooterLink = $('#sub-footer li:last').html().replace(/\|/g,'');
		$('#sub-footer li:last').empty().append(newLastFooterLink);
	}
	$('.adsense-wide').append('<iframe frameborder="0" width="475" height="85" src="'+template_url+'/the_ads.php?wide=true"></iframe>');
	$('.adsense-tall').append('<iframe frameborder="0" width="120" height="610" style="float:right;padding:0 0 0 10px" src="'+template_url+'/the_ads.php?tall=true"></iframe>');
	
	$('.adsense-tall-nofloat').append('<iframe frameborder="0" width="120" height="610" style="margin:20px 0 0 0;" src="'+template_url+'/the_ads.php?tall=true"></iframe>');
	
	
	$('.ie6 form').css('width','90%');
});

$(function(){
	// Sorting Code \\
	var where = '#archives-2'; //Where to put the generated code (starts with a ul!)
	var what = '#archives-2 li'; //What are we grabbing? Should almost be #archives li!
	var numerical_months = false;
	var oldest_newest = false;
	var the_years = new Array(); //All the years, even repeated
	var i = 0; //Will be used to add to the array
	var x = 0; //Will be used to check if the year already exists
	var current_item_year; //Saves the href.split val in a var
	
	$(what).parent().css('display','none');
	
	$(what).each(function(){
		current_item_year = $(this).children().attr('href').split('/')[3]; //Grabs year out of the href str
		x = i-1; //Last item's year
		if(current_item_year !== the_years[x]){ //check if the last item's year !== the current year
			the_years[i] = current_item_year; // If not, then add current_item_year to the array
			i++; //increment array item int
		}
	});
	
	if(oldest_newest){
		the_years.reverse(); //Sort newest to oldest years
	}

	for (var i=0; i<the_years.length; i++) {
		var the_year = the_years[i]; //The current year
		$(where).append('<ul class="new_year_set"><li><h3 class="new_year">'+the_year+'</h3><ul class="year_'+the_year+'"></ul></li></ul>');
		$(what+' a[href*="/'+the_year+'/"]').each(function(){
			if(numerical_months){
				var the_month = $(this).attr('href').split('/')[4];
			}else{
				var the_month = $(this).attr('title').split(' ')[0];
			}
			$('.year_'+the_year).append('<li><a href="'+$(this).attr('href')+'">'+the_month+'</a></li>');
		});
	}
	
	// End Sorting Code && Start animation code. \\
	$('.new_year').css('cursor','pointer').prepend('<span class="more_years">+ </span>').siblings('ul').css('display','none');
	$('.new_year').toggle(
		function(){
			$(this).children().empty().append('- ').parent().siblings('ul').slideDown();
		},
		function(){
			$(this).children().empty().append('+ ').parent().siblings('ul').slideUp();
		}
	);
});