// Place your application-specific JavaScript functions and classes here

// Image fading stuff
var img_index = 0;
images = new Array();
testimonials = new Array();

 //change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

//blend in the image smoothly
function blendimage(imageid, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

//set the testimonial text into the global array
function set_testimonial(text) {
	index = testimonials.length;
	testimonials[index] = new Array();
	testimonials[index][0] = text;
}

//set the testimonee into the global array
function set_testimonial_who(text, index) {
	testimonials[index][1] = text;
}
	
//print out the complete testimonial (consists of
//the testimonial itself and the testimonee
function get_testimonial(index){
	var result = "";
	var div1 = "<div class='testimonial'>";
	var div2 = "</div><div class='testimonial_who'>";
	var div3 = "</div>";
	
	result = div1 + testimonials[index][0] + div2 + testimonials[index][1] + div3 ;
	return result;
}

//from the home page loading, set a banner image
//to a global array
function set_img(image) {
	images.push(image);
}
	
//refresh the banner image
function refreshIt() {
	var div = document.getElementById('banner_image');
	var btn = document.getElementById('banner_tagline');
	var testimonial = document.getElementById('a_testimonial');
	var testimonial_count = testimonials.length;
	//make image transparent
	changeOpac(0, 'banner_image');
				
	switch (img_index) {
		case 0: 				
			div.style.backgroundImage = "url(" + images[1] + ")";
			btn.style.marginRight = "565px";
			btn.style.marginTop = "160px";			
			testimonial.innerHTML = get_testimonial(img_index % testimonial_count);
			img_index = 1;			
			break;
		 case 1:
			div.style.backgroundImage = "url(" + images[2] + ")";
			btn.style.marginRight = "415px";
			btn.style.marginTop = "150px";
			testimonial.innerHTML = get_testimonial(img_index % testimonial_count);
			img_index = 2;
			break;
		 case 2:
			div.style.backgroundImage = "url(" + images[3] + ")";
			btn.style.marginRight = "850px";
			btn.style.marginTop = "80px";
			testimonial.innerHTML = get_testimonial(img_index % testimonial_count);
			img_index = 3;
			break; 
		 case 3:
			div.style.backgroundImage = "url(" + images[0] + ")";
			btn.style.marginRight = "305px";
			btn.style.marginTop = "175px";
			testimonial.innerHTML = get_testimonial(img_index % testimonial_count);
			img_index = 0;
			break;
		 
		 default: break;
	}

	blendimage('banner_image',2000);
	setTimeout('refreshIt()',10000); // refresh every 10 secs
}

//AJAX Newsletter form
$(document).ready(function() {
	
	$('#submit').click(function () {
		alert("JQUERY took over!");
	});
	/*
	$(function() {
		$("#newsletter_form").dialog();
	});


	$('#get_newsletter').click(function() {
		$("#newsletter_form").dialog('open');
	});
	*/
});

function show_newsletter_form() {
	//$("#newsletter_form").dialog();
	document.getElementById("overlay").style.visibility = "visible";
	//Popup.show("newsletter_form");
	document.getElementById("newsletter_form").style.visibility = "visible";
}

function close_newsletter_form() {
	//$("#newsletter_form").dialog();
	document.getElementById("overlay").style.visibility = "hidden";
	//Popup.show("newsletter_form");
	var form = document.getElementById("newsletter_form");
	form.style.visibility = "hidden";
}





