var testimonials = new Array();
var quoter = new Array();
var currentQuote

$("document").ready(function() {
	update_links();
	
	$("#tbl_therapyArea tr:even").css("background-color", "#F6F6F6");
	
	$(".emailLink").attr("href", "mailto:info@quantum-med.com?Subject=Enquiry%20from%20Quantum%20Medical%20Website").html("info@quantum-med.com");
	
	$("#tbl_workingWith tr:even").css("background-color", "#E6F2E0");
	
	$('#cuttingEdge_swf span').flash({
	
        "src":"flash/banner.swf",
        "width":"420px",
        "height":"235px",
        "quality":"high",
        "wmode":"transparent",
        "classid":"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
        "codebase":"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=",
        "plugin":"http://get.adobe.com/flashplayer",
        "mime":"application/x-shockwave-flash",
        "version":"10"
    });

	
	$("ul.jsPop:last").css("margin-bottom", "0");
	
	//IF googlemap DIV exists then add map
	if($('#googlemap').length != 0)addGoogleMap();
	
	//IF googlemap DIV exists then add map
	if($('#cuttingEdge').length != 0)loadTestimonials();
	
	
});

function update_links()
{
	$("a[rel=external]").attr("target", "_blank");	
}

function show_hide(id)
{
	if ($("#crp" + id).prev().attr("class") == "squareBulletGrey")
	{
		$("div.jsPop").not("#crp" + id).hide().prev().attr("class", "squareBulletGrey");
		$("#crp" + id).show().prev().attr("class", "squareBulletGreen");
		
		return;
	}
	$("div.jsPop").not("#crp" + id).hide().prev().attr("class", "squareBulletGrey");
	$("#crp" + id).hide().prev().attr("class", "squareBulletGrey");
}

function addGoogleMap(){

	var map = new GMap2(document.getElementById("googlemap"));
	map.setCenter(new GLatLng(51.131154, 0.262839), 15);	
	
	map.addControl(new GSmallMapControl());
	
	var point = new GLatLng(51.131154, 0.262839);
	map.addOverlay(new GMarker(point));
}


function loadTestimonials() {
	
	$('body').append('<div id="quotesTemp"></div>');
	var path = window.location + "inc/sp_team_testimonials.php";

	$('#quotesTemp').load(path, function() {	  
		c = 0;
		$('#quotesTemp div p').each(function(index) {
			myID = Number($(this).parent().attr('id'))
			if(!testimonials[myID-1])testimonials[myID-1]= new Array('','')
			testimonials[myID-1][c] = $(this).html()
			c = (!c) ? 1 :0
		});
	  	$('#quotesTemp').remove();
	  	currentQuote = Math.floor((Math.random() * testimonials.length)-1);
		showQuote()

	})
	
	
}

function hideQuote() {
	$(".testimonial_mini").fadeOut(1000, function() {setTimeout("showQuote();", 200)});
}

function showQuote() {
	if(!testimonials[currentQuote])return
	quoteTxt = (currentQuote==4) ? "<span>"+testimonials[currentQuote][0]+"</span>" : "<p>"+testimonials[currentQuote][0]+"</p>"
	quotePerson = testimonials[currentQuote][1]
	$(".testimonial_mini").html('<div id="insideMiniTestimonial">'+quoteTxt+'<p class="testimonialPerson">'+quotePerson+'</p></div');
	$(".testimonial_mini").fadeIn(1000, function() {setTimeout("hideQuote();", 5000);});
	
	// VERTICALLY ALIGN DIV TAG
	myHeight = $(".testimonial_mini").height()
	myEHeight = $("#insideMiniTestimonial").height()
	offset = (myHeight-myEHeight)/2
	$('#insideMiniTestimonial').css("margin-top",offset+"px")
	
	if (currentQuote == (testimonials.length-1)) {
		currentQuote = 1;
	}
	else
	{
		currentQuote++;	
	}
}

function popUp(URL, myHeight, myWidth)
{
	day = new Date();
	id = day.getTime();
	myLeft = (screen.width-myWidth)/2;
	myTop = (screen.height-myHeight)/2;
	//myHeight=400;
	//myWidth=400;
	window.open(URL, "Loading"+id, 'top='+myTop+',left='+myLeft+'+,toolbar=0 status=0,resizable=0,Width='+myWidth+',height='+myHeight+',scrollbars=1');
}
