var boo = new Array();
var get_screenshots_url = "/ajax/video/get_screenshots?id=";
var video_location_subdomain = 'video'; 
function slide(){	
	id = (this.id).substr(1);
	
//	if(images[id]){
//		slide_callback(id);
//	} else {
	boo[id] = setTimeout(function(){
		$.ajax({
			type: "GET",
			url: get_screenshots_url + id,
			data: "id=".id,
			dataType: "html",
			cache: true,
			success: function(msg){
				$("body").append( msg );
				slide_callback(id);
			}
		});
	},150);
	$(this).bind('mouseout', function() {clearTimeout(boo[id]);});
//	}
}

function slide_callback(id){
	for(var i = 0; i < images[id].length; i++){
		$("#s" + id).append('<a href="' + base_url.replace(/http\:\/\//,"http://" + video_location_subdomain + ".") + id + '.html"><img src="' + images[id][i] + '" alt="" width="160" height="120"/>');
	}

	$("#s" + id).unbind("mouseenter", slide);

	$('#s' + id).cycle({
		fx:     'fade',
		speed:  300,		
		timeout: 500
	});

	$("#s" + id).bind("mouseenter", start);
	$("#s" + id).bind("mouseleave", pause);
}

function start(){
	id = (this.id).substr(1);
	$('#play-but-'+id).hide();
	$('#s' + id).cycle('resume');
	
}

function pause(){
	id = (this.id).substr(1);	
	$('#play-but-'+id).show();
	$('#s' + id).cycle('pause');
	
}

function getRand(){
    return parseInt(Math.random() * 15);
}

function rand_slide_start(){
	var items_arr = new Array();
	items_arr[0] = getRand();
	items_arr[1] = getRand();
	while(items_arr[1] == items_arr[0]){
		items_arr[1] = getRand();
	}
	items_arr[2] = getRand();
	while(items_arr[2] == items_arr[0] || items_arr[2] == items_arr[1]){
		items_arr[2] = getRand();
	}
	
	var iterator = 0;
	var id = new Array();
	for(i in images){
		for(var j = 0;j < 3;j++){
			if(items_arr[j] == iterator){
                id[j] = i;                
				$.ajax({
					type: "GET",
					url: get_screenshots_url + i,
					data: "id=".i,
					dataType: "html",
					cache: true,
					success: function(msg){
						$("body").append( msg );
					}
				});
			}
		}
		iterator++;
	}
    //setTimeout(function(){for(var i=0;i<3;i++){slide_callback(id[i]);}},1000);
	setTimeout(function(){slide_callback(id[1]);},1000);
}