var timer;
function prev_testimonial() {
	next_testimonial(true);
}
function next_testimonial(reverse) {
	var testimonials = $('#testimonials li');
	for (var i=0; i < testimonials.length; i++) {
		
		if ($(testimonials[i]).is(':visible')) {
			if (reverse) {
				var next = i-1;
				if (next < 0) { next = testimonials.length-1; }
			} else {
				var next = i+1;
				if (next == testimonials.length) { next = 0; }
			}
			$(testimonials[i]).fadeOut(200, function() {
				$(testimonials[next]).fadeIn(200);
			});
			break;
		}
	};
}
function validate_form(form) {
		var elements = $(form).find('.required:visible');
		var errors = new Array();
		elements.each(function(){
			if ($(this).hasClass('email')) {
				if ($(this).val()=='') {
					errors.push($(this).attr('name')+', is required');
					$(this).addClass('error');
				}
				if(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test($(this).val())==false) {
					errors.push($(this).attr('name')+', must be a valid email address');
					$(this).addClass('error');
				}
			} else if ($(this).hasClass('qty')) {
				if ($(this).val()=='' || $(this).val()=='0') {
					errors.push($(this).attr('name')+', is required');
					$(this).addClass('error');
				}
			} else if ($(this).hasClass('num')) {
				if ($(this).val()=='') {
					errors.push($(this).attr('name')+', is required');
					$(this).addClass('error');
				}
				if (isNaN($(this).val())) {
					errors.push($(this).attr('name')+', must be numeric');
					$(this).addClass('error');
				}
			} else {
				if ($(this).attr('type')=='checkbox') {
					if (!$(this).is(':checked')) {
						errors.push($(this).attr('name')+', is required');
						$(this).addClass('error');
					}
				} else {
					if ($(this).val()=='') {
						errors.push($(this).attr('name')+', is required');
						$(this).addClass('error');
					}
				}
			}
		});
		if (errors.length) {
			errors = errors.join("\n");
			return false;
		} else {
			return true;	
		}
	}
$(document).ready(function() {
		$('form#search_alums_form').submit(function() { 
			query = $('#query').attr('value');
			$.ajax({
					data: "query="+ query,
					type : "POST",
					url : '',
					success : function(data) {
						$('#search_results').html(data);
					}
			});
			return false;
		});
	$('#blackcat-thirteen').hover(
		function() {
			if ($('.what-is-this').length == 0) {
				var div = $('<div />');
				div
					.attr('class', 'what-is-this')
					.prependTo('#blackcat-thirteen')
					.animate({ 'opacity' : 1.0, 'top' : '25px' }, 300);
			} else {
				$('.what-is-this').animate({ 'opacity' : 1.0, 'top' : '25px' }, 300);
			}
		},
		function() { 
			$('.what-is-this').animate({ 'opacity' : 0.0, 'top' : '33px' }, 150, function() {
				$(this).remove();
			}); 
		}
	);	
	$('#logo_home').hover(
		function() {
			if ($('.home_page').length == 0) {
				var div = $('<div />');
				div
					.attr('class', 'home_page')
					.prependTo('#logo_home')
					.animate({ 'opacity' : 1.0, 'top' : '25px' }, 300);
			} else {
				$('.home_page').animate({ 'opacity' : 1.0, 'top' : '25px' }, 300);
			}
		},
		function() { 
			$('.home_page').animate({ 'opacity' : 0.0, 'top' : '33px' }, 150, function() {
				$(this).remove();
			}); 
		}
	);	
	$('#img_slider .slider_module').append('<img src=\"images/slider_overlay.png\" class=\"slider_overlay\"/>');
	$('#img_slider').jcarousel({ wrap: 'circular',animation:1000 });
	$('#testimonials li:not(:first)').hide();
	$('#testimonials li').each(function() { $(this).find('.content_box:last').addClass('last'); });
	$('ul.newsticker').css('left','930px');
	$('ul#ticker01 li').css('float','left').css('display','inline');
	$('ul#ticker01').liScroll();
	$('#box_01 a').append('<img src=\"images/grunge_01.png\" class=\"grunge\"/>');
	$('#box_02 a').append('<img src=\"images/grunge_02.png\" class=\"grunge\"/>');
	$('#box_03 a').append('<img src=\"images/grunge_03.png\" class=\"grunge\"/>');
	timer = setInterval(function() {
		$('div#img_slider.jcarousel-container .jcarousel-next-horizontal').trigger('click');
	}, 8000);
	$('div#img_slider.jcarousel-container .jcarousel-prev-horizontal').live('click',function() {
		//clearInterval(timer);
		prev_testimonial();
	});	
	$('div#img_slider.jcarousel-container .jcarousel-next-horizontal').live('click',function() {
		//clearInterval(i);
		next_testimonial(false);
	});
	$('#testimonials li:first').fadeIn(200);
	$('#textual_content ul').not('.reset').find('li').each(function() {
		$(this).html('<span>' + $(this).html() + '</span>');
	}).css('color', '#e3a809');
	$('#subnav li').not('.header').each(function() {
		var href = $(this).find('a').attr('href').split('/');
		href = href[href.length-1];
		var url = window.location.href;
		url = url.split('/');
		url = url[url.length-1].replace('#', '');
		if (url == href) {
			$(this).addClass('active');
		}
	});
	$('ul.testimonials a, ul.news a').fancybox({ 
		'width': '70%', 
		'height': '95%', 
		'type': 'iframe' 
	});
	$('.video_link').fancybox({ 
		'width': 600, 
		'height': 400,
		'titleShow': false,
		'type': 'iframe'
	});
	$(".youtube_link").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});
	$('a#blackcat-thirteen').fancybox({
		'width': 700,
		'height': '100%',
		'type': 'iframe',
		'titleShow': false,
		'padding': 7
	});
	$('input[type="checkbox"]').each(function() {
		var cb = $(this);
		var box = $('<div />');
		box.attr('class', 'checkbox').css({ 'display': 'inline', 'padding': '5px', 'margin-right': '0px' });
		$(this).css({ 'opacity': 0 }).wrap(box);
		$(this).click(function(event) {
			if ($(this).attr('checked')) {
				$(this).after('<div class="checkmark"></div>');
				$(this).siblings('.checkmark').click(function() {
					$(this).siblings('input').attr('checked', false);
					$(this).remove();
				});
			}
		});
		if ($(this).attr('checked')) {
			$(this).after('<div class="checkmark"></div>');
			$(this).siblings('.checkmark').click(function() {
				$(this).siblings('input').attr('checked', '');
				$(this).remove();
			});
		}
	});
	$('input[type="radio"]').each(function() {
		var rb = $(this);
		var box = $('<div />');
		box.attr('class', 'radio').css({ 'display': 'inline', 'padding': '5px', 'margin-right': '0px' });
		$(this).css({ 'opacity': 0 }).wrap(box);
		$(this).click(function() {
			$('input[name="' + $(this).attr('name') + '"]').each(function() {
				$(this).parents('.radio').removeClass('over');
			});
			$(this).parents('.radio').addClass('over');
		});
		if ($(this).attr('checked')) {
			$(this).parents('.radio').addClass('over');
		}
	});
	$('select').each(function() {
		// Check for multiple
		if ($(this).attr('multiple')) {
			return false;
		}
		
		if ($.browser.msie && $.browser.version.substr(0,1)<7) { return false; }
		var selectEl = $(this);
		var select = {
			width: $(this).width(),
			height: $(this).height(),
			top: $(this).offset().top,
			left: $(this).offset().left,
			name: $(this).attr('name')
		}
		if ($.browser.mozilla) { select.width += 15; }
		var box = $('<div />');
		var box_left = $('<div />');
		var text = $(this).find('option:first');
		$(box_left).attr('class', 'custom-select-left');
		$(box)
			.attr('class', 'custom-select')
			.css({ 'width': (select.width + 30)+'px' })
			.html(box_left);
			//.appendTo('body')
		$(selectEl)
			.css({ 'opacity': 0, 'position': 'absolute', 'left': '0px', 'top': '0px', 'width': (select.width+30)+'px' })
			.change(function() {
				$(selectEl).siblings('.custom-select-text').html($(this).parents('form').find('select[name="'+select.name+'"] option:selected').text());
			})
			.wrap(box);
		$('<div class="custom-select-text" style=" width: ' + (select.width + 15) + 'px">' + text.text() + '</div>').insertBefore('#'+selectEl.attr('id'));
		
		// Set initial value
		$(selectEl).siblings('.custom-select-text').html($(this).parents('form').find('select[name="'+select.name+'"] option:selected').text());
	});
	
	$('#pause_button a').click(function(event) {
		event.preventDefault();
		$(this).toggleClass('play');
		if (!$(this).hasClass('play')){
			timer = setInterval(function() {
		$('div#img_slider.jcarousel-container .jcarousel-next-horizontal').trigger('click');
	}, 8000);}
		else{
			clearInterval(timer);}
	});

																	
});


// VALIDATION SCRIPT:

jQuery(function($){
	$('form:has(.required)').live('submit', function(e){
		var cakeValidate = $(this).find('div.required:visible');
		var normalValidate = $(this).find('.required:visible:not(div)');
		var passed = true;
		
		if (normalValidate.length) {
			normalValidate.each(function(){
				if ($(this).hasClass('email')) {
					if ($(this).val()==''&&!$(this).hasClass('validated')) {
						$('<div/>').addClass('error-message').text('Please enter a '+ucwords($(this).attr('name'))).insertAfter($(this));
						$(this).addClass('validated');
						passed = false;
					} else if ($(this).val()!=''&&$(this).hasClass('validated')) {
						$(this).removeClass('validated');
						$(this).next('div.error-message').remove();
					}
					if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test($(this).val())==false&&!$(this).hasClass('validated')) {
						$('<div/>').addClass('error-message').text('Please enter a valid email for '+ucwords($(this).attr('name'))).insertAfter($(this));
						$(this).addClass('validated');
						passed = false;
					} else if ($(this).val()!=''&&/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test($(this).val())==true&&$(this).hasClass('validated')) {
						$(this).removeClass('validated');
						$(this).next('div.error-message').remove();
					}
				} else if ($(this).hasClass('num')) {
					if ($(this).val()==''&&!$(this).hasClass('validated')) {
						$('<div/>').addClass('error-message').text('Please enter a '+ucwords($(this).attr('name'))).insertAfter($(this));
						$(this).addClass('validated');
						passed = false;
					} else if ($(this).val()!=''&&$(this).hasClass('validated')) {
						$(this).removeClass('validated');
						$(this).next('div.error-message').remove();
					}
					if (isNaN($(this).val())&&!$(this).hasClass('validated')) {
						$('<div/>').addClass('error-message').text('Please enter a numeric value for '+ucwords($(this).attr('name'))).insertAfter($(this));
						$(this).addClass('validated');
						passed = false;
					} else if ($(this).val()!=''&&!isNaN($(this).val())&&$(this).hasClass('validated')) {
						$(this).removeClass('validated');
						$(this).next('div.error-message').remove();
					}
				} else {
					if ($(this).attr('type')=='checkbox') {
						if (!$(this).is(':checked')&&!$(this).hasClass('validated')) {
							$('<div/>').addClass('error-message').text(ucwords($(this).attr('name'))+' is required').insertAfter($(this));
							$(this).addClass('validated');
							passed = false;
						} else if ($(this).is(':checked')&&$(this).hasClass('validated')) {
							$(this).removeClass('validated');
							$(this).next('div.error-message').remove();
						}
					} else {
						if ($(this).val()==''&&!$(this).hasClass('validated')) {
							$('<div/>').addClass('error-message').text('Please enter a '+ucwords($(this).attr('name'))).insertAfter($(this));
							$(this).addClass('validated');
							passed = false;
						} else if ($(this).val()!=''&&$(this).hasClass('validated')) {
							$(this).removeClass('validated');
							$(this).next('div.error-message').remove();
						}
					}
				}
			});
			if (normalValidate.hasClass('validated')) {
				passed = false;	
			}
		}
		
		if (cakeValidate.length) {
			cakeValidate.each(function(){
				var _this;
				if ($(this).find('input').attr('type')=='checkbox') {
					this_ = $(this).find('input');
					if (!this_.is(':checked')&&!this_.hasClass('validated')) {
						$('<div/>').addClass('error-message').text(ucwords(this_.attr('name'))+' is required').insertAfter(this_);
						this_.addClass('validated');
						passed = false;
					} else if (this_.is(':checked')&&this_.hasClass('validated')) {
						this_.removeClass('validated');
						this_.next('div.error-message').remove();
					}
				} else if ($(this).find('input').attr('type')=='text') {
					this_ = $(this).find('input');
					name_ = ucwords(this_.attr('name'));
					if (name_=='Email') {
						if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(this_.val())==false&&!this_.hasClass('validated')) {
							$('<div/>').addClass('error-message').text('Please enter a valid email for '+ucwords(this_.attr('name'))).insertAfter(this_);
							this_.addClass('validated');
							passed = false;
						} else if (this_.val()!=''&&/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(this_.val())==true&&this_.hasClass('validated')) {
							this_.removeClass('validated');
							this_.next('div.error-message').remove();
						}
					} else {
						if (this_.val()==''&&!this_.hasClass('validated')) {
							$('<div/>').addClass('error-message').text('Please enter a '+name_).insertAfter(this_);
							this_.addClass('validated');
							passed = false;
						} else if (this_.val()!=''&&this_.hasClass('validated')) {
							this_.removeClass('validated');
							this_.next('div.error-message').remove();
						}
					}
				} else if ($(this).find('select').length) {
					this_ = $(this).find('select');
					if (this_.val()==''&&!this_.hasClass('validated')) {
						$('<div/>').addClass('error-message').text('Please enter a '+ucwords(this_.attr('name'))).insertAfter(this_);
						this_.addClass('validated');
						passed = false;
					} else if (this_.val()!=''&&this_.hasClass('validated')) {
						this_.removeClass('validated');
						this_.next('div.error-message').remove();
					}
				} else if ($(this).find('textarea').length) {
					this_ = $(this).find('textarea');
					if (this_.val()==''&&!this_.hasClass('validated')) {
						$('<div/>').addClass('error-message').text('Please enter a '+ucwords(this_.attr('name'))).insertAfter(this_);
						this_.addClass('validated');
						passed = false;
					} else if (this_.val()!=''&&this_.hasClass('validated')) {
						this_.removeClass('validated');
						this_.next('div.error-message').remove();
					}
				}
			});
			if (cakeValidate.find('.validated').length) {
				passed = false;	
			}
		}
		
		if (!passed) {
			alert('Please verify you entered all required information above.');
			e.preventDefault();
			return false;
		}
		
	});
});

function ucwords(str) {
	if (str.indexOf('][')>0) {
		matches = /data\[[^\]]*]\[([^\]]*)/.exec(str);
		str = matches[1];
	}
	return (str.replace('_',' ') + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
        return $1.toUpperCase();
    });
}

var mImg = 2;
var cImg = 0, iId;

                function image_change() {

                                $('#logo .rotate').each(function(){

                                                if ($(this).is(':visible')) $(this).fadeOut(2000);

                                });

                                if (cImg==(mImg-1)) cImg = -1;

                                cImg++;

                                var ci = 0;

                                var clicked = cImg;

                                $('#logo .rotate').each(function(){

                                                if (clicked==ci) $(this).fadeIn(2000);

                                                ci++;

                                });

                }

                setInterval('image_change();',4000); 
				
				
				

