var gallery_images;
var current_image = 0;

var faqs;

$(document).ready(function(){
 
	gallery_images = [
						{src: 'images/gallery/img-1.png', src_sm: 'images/gallery/img-1-sm.png', desc: 'Choose the week and day to visualize each workout on the same screen. Tap on "GO" to begin your workout.'},
						{src: 'images/gallery/img-2.png', src_sm: 'images/gallery/img-2-sm.png', desc: 'Add up to 100 songs right in the app. The total length of music is shown at the top.'},
						{src: 'images/gallery/img-3.png', src_sm: 'images/gallery/img-3-sm.png', desc: 'Workout screen shows you the time of your workout, time remaining in each interval. Screen locks automatically.'},
						{src: 'images/gallery/img-4.png', src_sm: 'images/gallery/img-4-sm.png', desc: 'Control music during your workout. Previous, next, and pause. The artist is also displayed.'},
						{src: 'images/gallery/img-5.png', src_sm: 'images/gallery/img-5-sm.png', desc: 'Adjust voice alerts and music volumes by tapping on the volume icon during your workout.'},
						{src: 'images/gallery/img-6.png', src_sm: 'images/gallery/img-6-sm.png', desc: 'During your workout you can post to friends on Facebook and Twitter by tapping on "Conversation Bubble" and selecting each icon.'},
						{src: 'images/gallery/img-7.png', src_sm: 'images/gallery/img-7-sm.png', desc: 'Publish your runs on Facebook and involve your friends for support and motivation. '},
						{src: 'images/gallery/img-8.png', src_sm: 'images/gallery/img-8-sm.png', desc: 'Post on Twitter and view others who have joined and who are going through the same training. Get feedback and motivation from others.'},
						{src: 'images/gallery/img-9.png', src_sm: 'images/gallery/img-9-sm.png', desc: 'Settings allows you to control alerts during your runs as well as music shuffle and playback.'},
						{src: 'images/gallery/img-10.png',src_sm: 'images/gallery/img-10-sm.png',desc: 'Help section provides answers to frequently asked questions.'}
					 ]

	faqs = [
		{title: 'What do I do if app is misbehaving?', body: 'Restart your iPhone or iPod touch. Restarting frees up memory on your device, which is the cause of a lot of issues that are easily fixed by a simple restart. If you are having problems with the app try this first!'},
		{title: 'How do I advance to the next day?', body: "To select the next day please slide the \"day slider\" at the bottom of the screen until the desired day is under the green background in the center. If the slider does not move when you slide your finger over it, please try restarting your iPhone."},
		{title: "How do I post to Facebook/Twitter?", body: "The app doesn't post to Facebook and Twitter automatically. You need to tap on the Facebook and Twitter buttons in order to confirm publishing. The buttons are revealed when you tap on the \"comment bubble\" button on the bottom of the workout screen - right next to the note button. If you don't see either Facebook / Twitter icon when you tap the \"comment bubble\" go to settings located in your app on the tab bar and slide to ON to enable the social networks. "},
		{title: 'Do you have an app for 10K?', body: "Yes, we have two 10K apps. Bridge to 10K is for graduates who've completed Couch to 5K and wish to increase their running distance to 10K. The plan takes 6 weeks to complete. <a href=\"http://blog.c25kapp.com/about-bridge-to-10k/\">Learn more about the Bridge to 10K app</a> or <a href=\"http://bit.ly/bskvrl\">download it from the App Store<a/>.<br/><br/> Ease into 10K is for people who have a certain fitness level already and want to train for the 10K distance. The plan takes 10 weeks to complete. <a href=\"http://blog.c25kapp.com/about-ease-into-10k/\">Learn more about the Ease into 10K app</a> or <a href=\"http://bit.ly/cpZ7jR\">download it from the App Store</a>."}
	]

	$("#short_reviews_source").bxSlider({
	    mode: 'slide',
	    auto: 'true',
	    speed: 1500,
	    pause: 3500,
	    width: 240,
	    wrapper_class: 'short_reviews_slider'
	}); 
 
 	$("#reviews_read_more").click(function() {
 		switch_content_reviews();
 	});
 	
 	$(".faq_link_all").click(function(){
 		switch_content_faq();
 	});
 	
 	$("#gallery_prev").click(function() {
 		gallery_switch(--current_image);
 	});
 	
 	 $("#gallery_next").click(function() {
 		gallery_switch(++current_image);
 	});
 	
 	$("#tweet").tweet({
     	join_text: "auto",
        avatar_size: 0,
        count: 3,
        auto_join_text_default: "we said,",
        auto_join_text_ed: "we",
        auto_join_text_ing: "we were",
        auto_join_text_reply: "we replied to",
        auto_join_text_url: "we were checking out",
        loading_text: "loading tweets..."
     });
     
     $("#blog").feedreader({
		targeturl: "blogproxy.aspx",
		items: 5,
		descLength: 15
	 });
	 
	 $(".faq_link").click(function(){
	 
	 	var faqid = $(this).attr('faqid');
	 	
	 	$("#popup_title").text(faqs[faqid].title);
	 	$("#popup_description").html(faqs[faqid].body);
	 	
	 	$.fn.colorbox({ inline: true, href: "#popup_content", opacity: 0.6, close: "", open: true }); 
	 });
	 
	 $("#email_link").colorbox({width:"90%", height:"90%", opacity: 0.6, iframe:true});
	 
	 $(".popup_close").click(function(){ $.fn.colorbox.close(); });
 
});

function gallery_switch(index)
{
	if(index >= 0 && index < gallery_images.length)
	{
		var g = gallery_images[index];
		
		$("#gallery_description").text(g.desc);
		$("#gallery_image").attr("src", g.src_sm);
	}
	else
	{
		current_image = 0;
		gallery_switch(current_image);
	}
}
 
function switch_content_reviews() 
{
	$("#content_title").text("App Store Reviews");
 	$("#content_body").load("reviews.html");
}

function switch_content_faq()
{
	$("#content_title").text("Frequently Asked Questions");
	$("#content_body").load("help.html");
}
