function fadeInImages(){
	$('img.fade_image_in').animate({opacity: 1.0}, 1000);
}

function slideShow(speed) {


	//append a LI item to the UL list for displaying caption

	//Set the opacity of all images to 0
	
	
	//Get the first image and display it (set it to full opacity)
	var items = jQuery('ul.slideshow li:not(.show,#slideshow-caption)');
	var itemscount= items.length;
	var first=items.first();
	first.animate({opacity: 1.0},2000);
	first.addClass('show');
	//var title=first.find('img').attr('title');
	//Get the caption of the first image from REL attribute and display it
	//jQuery('#slideshow-caption h3').html(title);
		
	//Display the caption
	//jQuery('#slideshow-caption').css({opacity: 0.7, bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery()',speed);
	
	//pause the slideshow on mouse over
	
}

function gallery() {


	//if no IMGs have the show class, grab the first image
	var current = (jQuery('ul.slideshow li.show')?  jQuery('ul.slideshow li.show') : jQuery('#ul.slideshow li:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	/*var items = jQuery('ul.slideshow li:.show');
	var itemscount= items.length;
	var next=jQuery(items.get(Math.round(Math.random()*(itemscount-1))));*/
	var next=(current.next().length ? current.next() : jQuery('ul.slideshow li:not(.show,#slideshow-caption)').first());
		
	//Get next image caption
	//var title = next.find('img').attr('title');	

	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Hide the caption first, and then set and display the caption
	//jQuery('#slideshow-caption').animate({bottom:-40}, 300, function () {
			//Display the content
	//		jQuery('#slideshow-caption h3').html(title);					
	//});	

	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');

}

function initSlideshow(){
	//$('#tmp_content_image img').css('display','none');
	$.ajax({
		type: "GET",
		url: "images.xml",
		dataType: "xml",
		success: function(xml) {
			$(xml).find('page').each(function(){
				if ($(this).attr('name')==pageFilename()){ 
					doc='<ul class="slideshow">';
					$(this).find('img').each(function(){
						doc+='<li><img src="'+$(this).attr('src')+'" /></li>';
					});
					doc+='</ul>';
					$('#tmp_content_image').html(doc);
					jQuery('ul.slideshow li').css({opacity: 0.0});
				}
			});
		}
	       });
	
}

function startSlideshow() {
	slideShow(5000);
}

function toggleContent(id){
	if ($('#payroll_info_content_'+id).hasClass('payroll_info_visible')) {
		$('#payroll_info_content_'+id).removeClass('payroll_info_visible').stop().slideUp();
	} else {
		$('.payroll_info_visible').removeClass('payroll_info_visible').stop().slideUp();
		$('#payroll_info_content_'+id).addClass('payroll_info_visible').stop().slideDown();
	}
}
function pageFilename(){
	var filename=location.pathname;
	filename=filename.substring(filename.lastIndexOf('/')+1,filename.lastIndexOf('.'));
	if (location.pathname.lastIndexOf('.')<=0)
		filename="index";
	return filename;
}

function initMainMenu() {
	$('#tmp_main_menu>li>ul').css('display','none');
	var filename=pageFilename();
	var menuitem=$('#menuitem_'+filename);
	if (menuitem.length) {
		menuitem.addClass('menuitem_selected');
		if(menuitem.parent().parent().parent().attr('id')=="tmp_main_menu"){
			menuitem.parent().css('display','block');
		}
	}
}

function submitCallbackForm() {
	var valid=true;
	var msg="";
	
	if ($('#company_name').val()=="") {
		msg+="* Company Name\n";
		valid=false;
	}
	if ($('#contact_name').val()=="") {
		msg+="* Contact Name\n";
		valid=false;
	}
	if ($('#email').val()=="") {
		msg+="* Email\n";
		valid=false;
	}
	if (valid) {
		$('#callback_form').submit();
	} else {
		alert("Please fill in the following fields:\n"+msg);
	}
}

$(document).ready(function(){
	$('img.fade_image_in').css('opacity',0);
	$('div.payroll_info_content').css('display','none');
	initMainMenu();
	initSlideshow()
});

