//**********************************************************************************************************************
/**
* COMPANY: Zipline Interactive
* EMAIL: infon@gozipline.com
* PHONE: 509-321-2849
* DESCRIPTION: This document contains programming required for the website templates.  Requires the jQuery library.
*/
//***********************************************************************************************************************

;
function stay_alive() {
	$.post("/index.php", { action: "stay_alive" } );
	setTimeout(stay_alive,'30000');
}


//***********************************************************************************************************************
//ON DOCUMENT READY FUNCTIONS
//***********************************************************************************************************************
$(function() {

	zPresentation(0, false);

	$(".player_photos a").lightBox();

	$(".chzn-select").chosen();

	/*
$('.featured_thumb').click(function() {
		var slide_num = $(this).attr("id");
		var id = slide_num.replace("slidethumb","");
		
		$(".featured_story_link:visible").fadeOut(300, function() {
			$('.slide').removeClass('slide_active');
			$(this).css("display", "none");
			$("#slide" + id).fadeIn(300, function() {
				$(this).css("display", "block");
				$(this).parent().addClass('slide_active');
			})
		})
	});
*/

	
 	$('#slide_control').cycle({
		fx:			'scrollHorz',
		timeout:	7000,
		speed:		1200,
		rev:		0,
		prev:		'#slider_previous',
		next:		'#slider_next'
	});

	//////////////////////////////////////////////////////////////////
	// Delete Icon
	//////////////////////////////////////////////////////////////////

	$('.comment_item').live('mouseover mouseout',function(event){
		if (event.type == 'mouseover') {
			$('.icon_x',this).show().live('mouseover mouseout',function(event){
				if (event.type == 'mouseover') {
					$(this).removeClass('off').addClass('on');
				} else {
					$(this).removeClass('on').addClass('off');
				}
			});
		} else {
			$('.icon_x',this).hide();
		}
	});
	
	$('.icon_x').live('click',function(){
		var parent 		= 'comment_item';
		var item 		= $(this).parent().get(0).id;
		var item_info 	= item.split('_');
		var plugin 		= item_info[0];
		var comment 	= item_info[1];
		var host = 'http://'+window.location.hostname+'/';

		$("#dialog").attr("title","Notice");
		$("#dialog").html("Are you sure you want to delete this item?");

		$("#dialog").dialog({ modal: true, buttons: { 
			"Cancel": function() { 
				$(this).dialog("close");
			},
			"Ok": function() {
				$(this).dialog("close");
				$.ajax({
					url: host+'index.php',
					data: 'action='+plugin+'_delete_comment&comment='+comment,
					success: function(){
						$('#'+item).fadeOut();
					}
				});
			} 
		}});
	});
	
	$('#sports_ticker').slideToggle();
	
	$('#forums_drop_nav').change(function(){
		var board = $(this).val();
		if(board != 0) {
			document.location.href = 'http://www.realdawg.com/forums/view/'+board+'/';
		}
	});

	stay_alive();

});

function zPresentation(timer, paused) {
	var slideTime = 7500;
	var iterationTimer = 500;
	var numImages = 3;
	
	
	if (typeof paused == 'undefined') {
		paused = false;
	}
	if (typeof timer == 'undefined') {
		timer = 0;
	}
	
	if (timer >= slideTime && paused == false) {
		//Slide the image
		var index = $('.home_slide_active').index();
		newIndex = index + 1;
		
		if (newIndex >= numImages) {
			newIndex = 0;
		}
		
		//alert(index + ', ' + newIndex);
		
		$('.home_slide').eq(index).fadeOut(300, function() {
			$('.home_slide_active').removeClass('home_slide_active');
			$('.home_slide').eq(newIndex).fadeIn(300);
			$('.home_slide').eq(newIndex).addClass('home_slide_active');
		});
		
		
		timer = 0;
	}
	
	
	$('.home_slide').hover(function() {
		paused = true;
	}, function() {
		paused = false;
	});
	
	$('.featured_thumb').click(function() {
		var thumbIndex = $(this).index();
		
		var thumbNewIndex = thumbIndex++;
		
		if (thumbNewIndex >= numImages) {
			thumbNewIndex = 0;
		}
		
		$('.home_slide_active').fadeOut(300, function() {
			$('.home_slide_active').removeClass('home_slide_active');
			$('.home_slide').eq(thumbNewIndex).fadeIn(300);
			$('.home_slide').eq(thumbNewIndex).addClass('home_slide_active');
		});
	
		timer = 0;
	});
	
	setTimeout(function() {
		if (paused == false) {
			timer += iterationTimer;
		}
	
		zPresentation(timer, paused);
	}, iterationTimer)
	
}

function keepAlive() {
	//ajax to a session saver
	var status = 'success';
	
	$.ajax({
		type: "POST",
		url: "index.php",
		data: {
			url: '/forums',
			action: 'keepalive'
		},
		error: function() {
			status = 'failure'
		}
	});
	
	if (status == 'success') {
		setTimeout(function() {
			keepAlive();
		}, 30000);
	}
}
