jQuery(document).ready(function() {

	str_optinbox = 'Your email...';
	str_searchbox = 'To search, type here and press enter...';

	jQuery('#search .search_form .text_input')
		.val(str_searchbox)
		.focus(function() { if (jQuery(this).val() == str_searchbox) { jQuery(this).val(''); } })
		.blur(function() { if (jQuery.trim(jQuery(this).val()) == '') { jQuery(this).val(str_searchbox); } })
	;

	setInterval('fade_slideshow()', 7000);

	jQuery('#optinbox input[name=cm-obttk-obttk]')
		.val(str_optinbox)
		.focus(function() { if (jQuery(this).val() == str_optinbox) { jQuery(this).val(''); } })
		.blur(function() { if (jQuery.trim(jQuery(this).val()) == '') { jQuery(this).val(str_optinbox); } })
	;

	jQuery('#optinbox input.submit-btn').click(function(event) {

		var pattern_email = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var email = jQuery('#optinbox input.text_input');

		if (jQuery.trim(email.val()) == '' || email.val() == str_optinbox || pattern_email.test(email.val()) == false) {
			email.css('border-color', '#900');
			email.pulse({ opacity: [0,1] }, 300, 2);
			return false;
		} else {
			email.css('border-color', '#AAA');
		}

	});

});

function fade_slideshow() {

	var $active = jQuery('#slideshow img.active');
	if (!$active.length) {
		$active = jQuery('#slideshow img:last');
    }

	var $next = $active.next().length ? $active.next() : jQuery('#slideshow img:first');

	$active.addClass('last-active');
	$next.css({ opacity: 0 }).addClass('active').animate({ opacity: 1 }, 2000, function() {
		$active.removeClass('active last-active');
	});

}

/*
 * Pulse plugin for jQuery 
 * http://james.padolsey.com/javascript/simple-pulse-plugin-for-jquery/
 */
jQuery.fn.pulse=function(c,d,e,f,g){if(isNaN(e)){g=f;f=e;e=1}var h=jQuery.speed(d,f,g),queue=h.queue!==false,largest=0;
for(var p in c){largest=Math.max(c[p].length,largest)}h.times=h.times||e;return this[queue?'queue':'each'](function(){
var b={},opt=jQuery.extend({},h),self=jQuery(this);pulse();function pulse(){var a={},doAnimate=false;for(var p in c){
b[p]=b[p]||{runs:0,cur:-1};if(b[p].cur<c[p].length-1){++b[p].cur}else{b[p].cur=0;++b[p].runs}if(c[p].length===largest){
doAnimate=opt.times>b[p].runs}a[p]=c[p][b[p].cur]}opt.complete=pulse;opt.queue=false;if(doAnimate){self.animate(a,opt)}
else{h.complete.call(self[0])}}})};

