$(document).ready(function() {

	var page = $('body').attr('class');
	page = page.split(" ");	// GLOBAL PAGE CLASS
	var taxData = null; // USED FOR GLOBAL TAX PROCESSING
	var invpiceData = null; // USED FOR GLOBAL INVOICE VIEWING
	var isError = new Array(); // GLOBAL IS ERROR ARRAY

	var playSlideshow =  setInterval("slideSwitch()", 5000);
	
	if (page[0] == 'business-service') {
		playSlideshow;
		$('.slide-show-buttons .last').click(function(){
			stop();
			clearInterval(playSlideshow);
			slideLast();
			return false;
		});
		$('.slide-show-buttons .next').click(function(){
			stop();
			clearInterval(playSlideshow);
			slideNext();
			return false;
		});
	}
	
	/* NEW STARS ON HOMEPAGE */
	$("#ratelinks li a").click(function(){
		
		var rating = $(this).attr('id').split("-");
		$.ajax({
			url: '/index.php',
			type: "GET",
			data: ({
				call: 'sr',
				method: 'business',
				i: rating[1],
				rating: rating[0]
			}),
			async: false,
			success: function(data) {
				if (data == 0) {
				} 
				else if (data == 1) {
					$(this).modal({
						width: 415,
						height: 520,
						src: '/modal_boxes/submit_a_review.php?bizid=' + rating[1] + '&rating=' + rating[0]
					}).open();
					
					$("#current-rating-"+rating[1]).width((rating[0]*rating[2]));
				} 
				else if (data == 2) { 
					$(this).modal({
						width: 375,
						height: 165,
						src: '/modal_boxes/please_login.php'
					}).open();
				};
			}
		});
	});


});


function slideSwitch() {
	
	var $active = $('.business-service .slideshow img.active');

	if ($active.length == 0) $active = $('.business-service .slideshow img:last');

	var $next = $active.next().length ? $active.next() : $('.business-service .slideshow img:first');
	$active.addClass('last-active');

	$next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() {
		$active.removeClass('active last-active');
	});
	
}

function slideNext() {

	var $active = $('.business-service .slideshow img.active');

	if ($active.length == 0) $active = $('.business-service .slideshow img:last');

	var $next = $active.next().length ? $active.next() : $('.business-service .slideshow img:first');
	$active.addClass('last-active');

	$next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() {
		$active.removeClass('active last-active');
	});

}

function slideLast() {

	var $active = $('.business-service .slideshow img.active');

	if ($active.length == 0) $active = $('.business-service .slideshow img:first');

	var $next = $active.prev().length ? $active.prev() : $('.business-service .slideshow img:last');
	$active.addClass('last-active');

	$next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() {
		$active.removeClass('active last-active');
	});

}
