function goToLocation(val) {
	if (val!="Other") {
		window.location=SITE_URL+'/'+val+'.htm';
	}
}

function toggleAllBubbles() {
	for (var i=2;i<20;i++) { // dont hide the first one and assume there may be 20 areas (may need tweaking)
		if (el=document.getElementById('area'+i)) {
			if (el.style.display=='block') {
				el.style.display='none';
			}
		}
	}
}

function emailFriend(site,address,expert,expert2,title,question,time) {
	if (site) {
		var to = "<Your friends email address here>";
		var sub = title+" recommendation - Ask "+expert+" a free question";
		var msg = "Hello there, \n"
					+ "Welcome to "+title+" - Here you can ask "+expert+" a question and get a response within "+time+" minutes. Our service has been recommended to you by one of your friends.  To ask a real "+expert2+" a free "+question+" question with no obligation and\n "
					+ "privacy guaranteed, visit us at http://"+address;
	}
	else {
		var to = "<Your friends email address here>";
		var sub = "Ask a recommendation - Ask an expert a free question";
		var msg = "Hello there, \n"
					 + "Welcome to Ask a - Where you can find Free Expert Advice. \n "
					 + "Ask our Experts a question and get a response within 60 minutes. \n "
					 + "Our service has been recommended to you by one of your friends. \n "
					 + "To ask an Expert a free question with no obligation and privacy guaranteed, \n "
					 + "visit us at http://www.aska.co.uk";
	}
	win = window.open('mailto:'+to+'?subject='+sub+'&body='+msg,'email_window');
	if (win && win.open && !win.closed) {
		win.close();
	}
}

function showOther(v) {
	var el = document.getElementById("selectOther");
	if (v=="Other") {
		el.style.display="block";
	}
	else {
		el.style.display="none";
	}
}

function changeBubble(name) {
	var text,bg;
	switch (name) {

		case "uppity":
			text = "I would like to have my question answered by a professional for a change.";
			bg = "images/content/about/mr_uppity_circle.png";
			break;
		case "worry":
			text = "I'm losing sleep over my problems so I'd like honest advice so that I don't get into any more trouble.";
			bg = "images/content/about/mr_worry_circle.png";
			break;
		case "late":
			text = "I'd like to be able to get all the information I need at my convenience - whatever time of the day that may be.";
			bg = "images/content/about/miss_late_circle.png";
			break;
		case "shy":
			text = "I don't like talking to people I don't know so I'd like to ask my questions without having to see the person answering them.";
			bg = "images/content/about/miss_shy_circle.png";
			break;
		case "nosey":
			text = "I'd like to see what other people think of a service before I use it.";
			bg = "images/content/about/mr_nosey_circle.png";
			break;
		case "busy":
			text = "I'd like to get my answers faster.";
			bg = "images/content/about/mr_busy_circle.png";
			break;
		case "chatter":
			text = "I'd like to have more space to type in my full question...";
			bg = "images/content/about/mr_chatterbox_circle.png";
			break;
		case "muddle":
			text = "I'd like to be given advice that was clear and simple.";
			bg = "images/content/about/mr_muddle_circle.png";
			break;
		case "greedy":
			text = "I want to ask more than one question and get an answer for free.";
			bg = "images/content/about/mr_greedy_circle.png";
			break;
	}
	var el = document.getElementById("bubble");
	el.style.backgroundImage="url("+bg+")";
	el.innerHTML = '<p>"'+text+'"</p>';
}

function showEmailLive() {
	window.location = SITE_URL + "/tell-me-when-theyre-live";
}

function addFriend() {
	var row = document.getElementById('ctable1').insertRow(friendcount+1);
	var c1 = row.insertCell(0);
	var c2 = row.insertCell(1);
	var c3 = row.insertCell(2);
	var c4 = row.insertCell(3);
	var c5 = row.insertCell(4);
	var c6 = row.insertCell(5);
	var c7 = row.insertCell(6);
	friendcount++;
	c2.innerHTML='<input type="text" class="short" name="friendname['+friendcount+']">';
	c4.innerHTML='<input type="text" class="long" name="friendemail['+friendcount+']">';
	c6.innerHTML='<input type="text" class="long" name="friendemailconfirm['+friendcount+']">';
}

function showLightbox(s) {
	if (s) {
		var el;
		switch (s) {
			case 'www.rightsolicitor.co.uk':
				el = 'rs';
				break;
			case 'www.enhancement.co.uk':
				el = 'en';
				break;
			case 'www.financialadvice.co.uk':
				el = 'fa';
				break;
			case 'www.compensationclaims.co.uk':
				el = 'cc';
				break;
			case 'www.whiplash.co.uk':
				el = 'wl';
				break;
			case 'www.ask-an-accountant.co.uk':
				el = 'aa';
				break;
			case 'www.ask-a-builder.co.uk':
				el = 'ab';
				break;
			case 'www.ask-an-ivf-consultant.co.uk':
				el = 'vf';
				break;
			case 'www.ask-a-mechanic.co.uk':
				el = 'mc';
				break;
			case 'www.ask-a-nutritionist.co.uk':
				el = 'nu';
				break;
			case 'www.ask-a-vet.co.uk':
				el = 'vt';
				break;
			case 'www.ask-a-personal-trainer.co.uk':
				el = 'pt';
				break;
			case 'www.debtmanagementguide.co.uk':
				el = 'dm';
				break;
			case 'www.ask-a-plumber.co.uk':
				el = 'pb';
				break;
			case 'www.ask-a-travel-expert.co.uk':
				el = 'te';
				break;
			case 'www.ask-a-hairdresser.co.uk':
				el = 'hd';
				break;
			case 'www.ask-a-life-coach.co.uk':
				el = 'lc';
				break;
			case 'www.ask-a-chef.co.uk':
				el = 'cf';
				break;
			case 'www.ask-a-wedding-planner.co.uk':
				el = 'wp';
				break;
			case 'www.ask-a-gardener.co.uk':
				el = 'gd';
				break;
		}
		if (el) {
			toggleVisibility('lightbox');
			toggleVisibility(el);
		}
	}
}

$(function(){

	$('#slider').movingBoxes({
		startPanel   : 3,      // start with this panel
		width        : 900,    // overall width of movingBoxes (not including navigation arrows)
		panelWidth   : 0.24,     // current panel width
		reducedSize  : 0.7,       // non-current panel size
		buildNav     : true,
		fixedHeight  : true,// if true, navigation links will be added
		navFormatter : function(){ return "&#9679;"; } // function which returns the navigation text for each panel
	});

	// Add a slide
	var imageNumber = 0,
	panel = '',
	// to test adding/removing panels to the second slider, comment out the line above and uncomment out the line below - slider-two uses divs instead of UL & LIs
	// panel = '<div><img src="images/*.jpg" alt="picture" /><h2>News Heading #<span>*</span></h2><p>A very short exerpt goes here... <a href="#">more</a></p></div>',
	slider = $('#slider'); // $('#slider-two'); // second slider

	$('button.add').click(function(){
		slider
		.append( panel.replace(/\*2/g, ++imageNumber).replace(/\*1/g, (imageNumber%7 + 1)) )
		.movingBoxes(); // update movingBoxes
	});

	// Remove a slide
	$('button.remove').click(function(){
		if (slider.data('movingBoxes').totalPanels > 1) {
			slider.find('.mb-panel:last').remove();
			slider.movingBoxes(); // update the slider
		}
	});

	// Set up demo external navigation links
	// could also set len = $('#slider-one').getMovingBoxes().totalPanels;
	var i, t = '', len = $('#slider .mb-panel').length + 1;
	for ( i=1; i<len; i++ ){
		t += '<a href="#" rel="' + i + '">' + i + '</a> ';
	}
	$('.dlinks')
		.find('span').html(t).end()
		.find('a').click(function(){
			slider.movingBoxes( $(this).attr('rel') );
			return false;
		});

	// Report events to firebug console
	$('.mb-slider').bind('initialized.movingBoxes initChange.movingBoxes beforeAnimation.movingBoxes completed.movingBoxes',function(e, slider, tar){
		// show object ID + event in the firebug console
		// namespaced events: e.g. e.type = "completed", e.namespace = "movingBoxes"
		if (window.console && window.console.firebug){
			var txt = slider.$el[0].id + ': ' + e.type + ', now on panel #' + slider.curPanel + ', targeted panel is ' + tar;
			console.debug( txt );
		}
	});

});

/** our story transitions **/
function showNextStage(n) {
	$('#special_'+n).show("slow");
	$('#nextButton_'+(n-1)).hide("slow");
}
