function photo(id)
{
	this.id = id;
	this.state = 'up';
	this.offset = 0;

	this.slide = function() 
	{	
		scope = this;
		
		if (this.state == 'up') {
			this.offset += 20;				
		} else if (this.state == 'down') {			
			this.offset -= 20;
		}
		
		document.getElementById('click_prompt_div_'+this.id).style.display = 'none';		

		document.getElementById('container_div_'+this.id).style.height = (115 + this.offset)+'px';
		document.getElementById('image_div_'+this.id).style.height = (115 + this.offset)+'px';
		document.getElementById('image_'+this.id).style.top = (-200 + this.offset)+'px';

		if (this.offset == 200) {
			this.state = 'down';
			document.getElementById('slide_button_'+this.id).value = 'hide image';
		} else if (this.offset == 0) {			
			this.state = 'up';
			document.getElementById('slide_button_'+this.id).value = 'expand image';			
		} else {
			setTimeout(function() { scope.slide(); }, 50);						
		}					
	}
	
	this.handle_prompt = function(direction)
	{
		if (direction == 'out') {
			document.getElementById('click_prompt_div_'+this.id).style.display = 'none';
		} else {
			if (this.state == 'up') {
				document.getElementById('click_prompt_div_'+this.id).style.display = 'block';
			}
		}
	}
}

function display_install_success_dialog()
{
	var html = 'Success!';
	var dialog = new Dialog('Step of 1 of 2 Complete!', html, 'Close', null);
}

function display_install_step_2_dialog()
{
	var html = '<strong>SUCCESS - You are almost done!</strong>  The image has been uploaded to your facebook.  Now you just have to place it on your profile using the following steps…';
	var dialog = new Dialog('Step of 1 of 2 Complete!', html, 'Continue', null);
}

function display_install_needs_publish_stream_dialog(photo_id)
{
	var html = 'In order to post this image to your Facebook account, we need you to grant us "Publish Stream" permissions within Facebook.  Click the button below, and try again please! :)';
	var dialog = new Dialog('Uh oh…there was a problem!', html, 'Continue', null);
	
	dialog.onconfirm = function() {
		window.location = 'http://www.pikzor.com/photo/'+photo_id+'/install?route_to_facebook=1';
		this.hide();
	}
}

function display_install_login_refused_dialog(photo_id)
{
	var html = 'In order to post this image to your Facebook account, we need you to connect this app to your facebook account!  Click the button below, and try again please! :)';
	var dialog = new Dialog('Uh oh...there was a problem!', html, 'Continue', null);

	dialog.onconfirm = function() {
		window.location = 'http://www.pikzor.com/photo/'+photo_id+'/install?route_to_facebook=1';
		this.hide();
	}
}

function install_photo(photo_id)
{
	var upload_was_successful = false;

	var html = 'please wait...';
	var dialog = new Dialog('Installing Cover Photo…', html, null, null);

	var self = {count:1};	
	self.do_something = function()
	{
		alert(++self.count);
		setTimeout(function() { self.do_something() }, 1000);
	}
	
	//self.do_something();
	
    var ajax = new Ajax();
    ajax.response_type = 'RAW';
    ajax.post('http://'+window.location.hostname+'/ajax/countdown_content', {'photo_id':photo_id}, function(data) {

	   	dialog.set_content(data);

		var self = {count:1};	
		self.do_something = function()
		{
			self.count++;
			if (self.count <= 100) {
				document.getElementById('progress_div').style.width = self.count+'%';
				setTimeout(function() { self.do_something() }, 300);
			} else {
				if (upload_was_successful) {
					window.location = 'http://www.pikzor.com/photo/'+photo_id+'/install_step_2';
				} else {
					alert("Uh oh…there was a problem!  Please try again!");
				}
			}
		}
		self.do_something();
	   	
    });
	
    var ajax = new Ajax();
    ajax.response_type = 'RAW';
    ajax.post('http://'+window.location.hostname+'/ajax/send_photo', {'photo_id':photo_id}, function(data) {
		if (data == 1) {
			upload_was_successful = true;
		}
    });
	
}

function initialize_paginator(current_page, total_pages)
{
	if (current_page > 1) {
		var previous_button = document.getElementById('paginator_button_previous');
		previous_button.onclick = function() {
			window.location = 'http://www.pikzor.com/'+(current_page - 1);
		}
		previous_button.style.cursor = 'pointer';
		add_class_name(previous_button, 'paginator_button_enabled');
		previous_button.onmouseover = function() {
			add_class_name(previous_button, 'paginator_button_active');
		}
		previous_button.onmouseout = function() {
			remove_class_name(previous_button, 'paginator_button_active');
		}
	}

	if (current_page < total_pages) {
		var next_button = document.getElementById('paginator_button_next');
		next_button.onclick = function() {
			window.location = 'http://www.pikzor.com/'+(current_page + 1);
		}
		next_button.style.cursor = 'pointer';
		add_class_name(next_button, 'paginator_button_enabled');
		next_button.onmouseover = function() {
			add_class_name(next_button, 'paginator_button_active');
		}
		next_button.onmouseout = function() {
			remove_class_name(next_button, 'paginator_button_active');
		}
	}
	
	for (var i = 1; i <= total_pages; i++) {
		(function(page_number) {
			var button = document.getElementById('paginator_button_page_'+page_number);
			if (page_number != current_page) {
				button.onclick = function() {
					window.location = 'http://www.pikzor.com/'+page_number;
				}
				button.style.cursor = 'pointer';
				add_class_name(button, 'paginator_button_enabled');
				button.onmouseover = function() {
					add_class_name(button, 'paginator_button_active');
				}
				button.onmouseout = function() {
					remove_class_name(button, 'paginator_button_active');
				}
			} else {
				add_class_name(button, 'paginator_button_current');
			}
		})(i);
	}

}


