/*  File: basic.js          */
/*  By:   Jeremy Tredway    */
/*  Ver:  2008-02-17        */

/********************************
  the following routines require 
    jquery.js
*********************************/


// obfuscate address function
function obfsMail(s,e,h,c) {
	var x = e + '&#x40;' + h;
	if (c == '') { c = x; }
	if (c == 'icon') { c = ''; }
	var y = 'href="ma' + 'ilto:' + x + '"';
	var z = (s == '') ? ('<a ' + y + '>' + c + '</a>') : ('<a class="' + s + '\' ' + y + '>' + c + '</a>');
	return z;
}


// onload routines
$(function(){

	// add additional structure to the DOM (styled via layout.css)
	$('.rnd').wrapInner('<div class="rnd_top"><div class="rnd_bot"><div class="rnd_inr"></div></div></div>');
	$('.box').wrapInner('<div class="box_top"><div class="box_bot"><div class="box_inr"></div></div></div>');

	// initialize drop-down menus
	$('ul.sf-menu').superfish({
		delay: 100,
		animation: {height:'show'},
		speed: 'fast',
		autoArrows: false,
		dropShadows: false
	});

	// PNG fix for IE6
	$('.png_trans').pngfix();

	// initialize tabs
	$('.tabs_list').tabs();

	// set search form parameters
	var DEF_VAL = 'Search';
	var search_key = document.getElementById('search');
	if (search_key.value == '') {
		search_key.value = DEF_VAL;
	}
	$('#search').focus(function() {
		$('#search').attr('value','');
	});
	$('#search').blur(function() {
		if (search_key.value == '') {
			$('#search').attr('value',DEF_VAL);
		}
	});

	// initialize toggled modules
	$('.toggle').find('.toggle_target').css({'display':'none'});
	$('.toggle').find('.toggle_link').each(function() {
		$(this).click(function() {
			$(this).parent().toggleClass('toggle_on');
			$(this).next('.toggle_target').toggle();
			return false;
		});
	});

	// initialize obfuscated addresses
	$('.obfmail').each(function() {
		var $this = $(this);
		var params = $this.attr('rel').split(':');
		if (params[0] == 'mail') {
			var addr = obfsMail('',params[1],params[2],'');
		}
		$this.html(addr);
	});

	// initialize email icons
	$('.obfmail_icon').each(function() {
		var addr = 'sales' + '@' + 'petzent.com';
		$(this).find('img').attr({ title:'Send an email to ' + addr});
		$(this).click(function() {
			parent.location = addr;
		});
	});

	// initialize striped tables
	$('.striped').each(function() {
		$(this).find('tr:even').addClass('alt');
	});

});

