var num_sites = 10;
var j = 0;
sites = new Array (num_sites);
var current_id = 0;

for (i = 0; i < sites.length; ++ i) {
	sites [i] = new Array(4);
}

//Oscar's Gastropub
sites[j][0] = 'Oscar\'s Gastropub';
sites[j][1] = 'oscarsgastropub';
sites[j][2] = 'http://oscarsgastropub.com';

//Fitso
j++;
sites[j][0] = 'Fitso';
sites[j][1] = 'fitso';
sites[j][2] = 'http://fitso.com';

//Robot Mafia
j++;
sites[j][0] = 'Robot Mafia';
sites[j][1] = 'bixbyrobotics';
sites[j][2] = 'http://bixbyrobotics.org';

// Sam Walker Photography
j++;
sites[j][0] = 'Sam Walker Photography';
sites[j][1] = 'samwalkerphotography';
sites[j][2] = 'http://swalkerphotos.com';

// Storehouse Financial
j++;
sites[j][0] = 'Storehouse Financial Group';
sites[j][1] = 'storehouse';
sites[j][2] = 'http://storehousefg.com/';
	
// Foci
j++;
sites[j][0] = 'Foci Photography';
sites[j][1] = 'foci';
sites[j][2] = 'http://fociphotography.net/';

//Freddie's Steak House
j++;
sites[j][0] = 'Freddie\'s Steak House';
sites[j][1] = 'freddies';
sites[j][2] = 'http://freddiessteakhouse.com/';

//Steak 2 Go
j++;
sites[j][0] = 'Steak 2 Go';
sites[j][1] = 's2g';
sites[j][2] = 'http://steak-2-go.com';

// Wade's RV Clinic
j++;
sites[j][0] = 'Wade\'s RV Clinic';
sites[j][1] = 'wadesrv';
sites[j][2] = 'http://wadesrvclinic.com';

// Mix It Up
j++;
sites[j][0] = 'Mix It Up Entertainment';
sites[j][1] = 'mixitup';
sites[j][2] = 'http://mixitupent.com';

for (i = 0; i < sites.length; ++ i) {
	$('#screenshots').append('<a href="#" target="_new" id="site_url_'+i+'"><img class="screenshot" id="screenshot_'+i+'" src="images/screenshots/'+sites[i][1]+'.jpg" alt="Site designed by nFuse Technology." /></a>');
}

function onAfter(curr,next,opts) {
	current_id = opts.currSlide;
	changeDetails(current_id);
}

function changeDetails(id) {
	$('#site_title').html(sites[id][0]);
	$('#site_url').attr('href',sites[id][2]);
	$('#site_url_'+id).attr('href',sites[id][2]);
	$('#site_info').html($('#'+sites[id][1]).html());
}

function pause(hover) {
	$('#screenshots').cycle('pause');
	$('.pause').attr('playing','false');
	$('.pause img').attr('src','images/play'+hover+'.png');
}

function play(hover) {
	$('#screenshots').cycle('resume',true);
	$('.pause').attr('playing','true');
	$('.pause img').attr('src','images/pause'+hover+'.png');
}

$(document).ready(function() {
    $('#screenshots').cycle({
		fx: 'fade',
		after: onAfter,
		speed: 'fast'
	});
	
	$('.pause').hover(function() {
		if ($('.pause').attr('playing') == 'true') {
			$('.pause img').attr('src','images/pause_hover.png');			
		} else {
			$('.pause img').attr('src','images/play_hover.png');
		}
	}, function() {
		if ($('.pause').attr('playing') == 'true') {
			$('.pause img').attr('src','images/pause.png');			
		} else {
			$('.pause img').attr('src','images/play.png');
		}
	});
	
	$('.pause').click(function(e) {
		e.preventDefault();
		if ($('.pause').attr('playing') == 'true') pause('_hover');
		if ($('.pause').attr('playing') == 'false') play('_hover');
	});

	$('.previous').hover(function() {
		$('.previous img').attr('src','images/previous_hover.png');
	}, function() {
		$('.previous img').attr('src','images/previous.png');
	});

	$('.previous').click(function(e) {
		e.preventDefault();
		pause('');
		if (current_id == 0) {
			current_id = num_sites - 1;
		} else {
			current_id--;
		}
		$('#screenshots').cycle(current_id);
		changeDetails(current_id);
	});

	$('.next').hover(function() {
		$('.next img').attr('src','images/next_hover.png');
	}, function() {
		$('.next img').attr('src','images/next.png');
	});
	
	$('.next').click(function(e) {
		e.preventDefault();
		pause('');
		if (current_id == num_sites - 1) {
			current_id = 0;
		} else {
			current_id++;
		}
		$('#screenshots').cycle(current_id);
		changeDetails(current_id);
	});
	
	$('.screenshot').hover (function() {
		$(this).css('border','2px solid #777777');
	}, function() {
		$(this).css('border','2px solid #cccccc');
	});
});