/*var big_pictures_dir = "pictures/big/";
var small_pictures_dir = "pictures/small/";
var big_pictures_list = new Array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg","8.jpg","9.jpg");
var small_pictures_list = new Array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg","8.jpg","9.jpg");*/
var path_to_icons='http://www.clevereveassets.com/js/lightbox/';
var hover_opacity_div = 80;
var hover_div_color = "#5A5A5A";
var main_list_window_border = "1px solid black";
var main_list_window_background_color = "#ffffff";

var image_width='720px';
var image_height='480px';

var check_view_picture_scroller = 0;
var ico_slider_interval = 0;
var slider_step = 5;
var slider_time_out = 20;

var main_picture_zoom = 6;
var main_picture_zoom_step = 1;

var main_picture_press = 0;

var first_time_show = 0;
var first_x = 0;
var first_y = 0;
// Make hover div
function make_hover_div(){
if(document.getElementById("main_hover_div")){
	elem = document.getElementById("main_hover_div"); 
	elem.parentNode.removeChild(elem); 	
	elem = document.getElementById("control_hover_div"); 
	elem.parentNode.removeChild(elem); 	
}	
if(!document.getElementById("main_hover_div")){
	var hover_div = document.createElement("div");
		hover_div.id = "main_hover_div"; 
		hover_div.style.position = "absolute";
		hover_div.style.top = "0px";
		hover_div.style.left = "0px";
		hover_div.style.opacity	= hover_opacity_div / 100;
		hover_div.style.MozOpacity = hover_opacity_div / 100;	
		hover_div.style.KhtmlOpacity = hover_opacity_div / 100;	
		hover_div.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+hover_opacity_div+")";
		hover_div.style.backgroundColor = hover_div_color;	
		hover_div.style.zIndex = "10000";
		hover_div.onclick = function(){
			closeSlider();
			}	
		document.body.appendChild(hover_div);
	var control_div = document.createElement("div");
		control_div.id = "control_hover_div";
		control_div.style.width = "100%";
		document.body.appendChild(control_div);		 
	}
		document.getElementById("main_hover_div").style.width = getElementPosition("control_hover_div").width + "px";
		document.getElementById("main_hover_div").style.height = getElementPosition("control_hover_div").top + "px";	
}
function closeSlider(){
			if(document.getElementById( 'flowPlayerEmbed' )){
				document.getElementById( 'flowPlayerEmbed' ).style.display = 'block';
			}
			document.body.removeChild(document.getElementById("main_hover_div"));
			document.body.removeChild(document.getElementById("control_hover_div"));			
			document.body.removeChild(document.getElementById("slider_main_window"));
			check_view_picture_scroller = 0;
			first_time_show = 0;
			main_picture_slide_zm = 0
			}	
// Elements attributes
function getElementPosition(elemId)
{
    var elem = document.getElementById(elemId);
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
    var l = 0;
    var t = 0;
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }
    return {"left":l, "top":t, "width": w, "height":h};
}
function make_slide_show(){
	if(check_view_picture_scroller == 0){
		if(document.getElementById( 'flowPlayerEmbed' )){
			document.getElementById( 'flowPlayerEmbed' ).style.display = 'none';
		}
		check_view_picture_scroller = 1;
		make_hover_div();
		create_slider_main_window();				
	}
}
function create_slider_main_window(){
	var slider_main_window = document.createElement("div");
		slider_main_window.id = "slider_main_window"; 
		slider_main_window.style.position = "absolute";
		slider_main_window.style.border = main_list_window_border;		
		slider_main_window.style.backgroundColor = main_list_window_background_color;
		slider_main_window.style.textAlign = "center";
		slider_main_window.style.zIndex = "10001";		
		slider_main_window.style.display = "inline";
		slider_main_window.style.paddingTop = '5px';
		slider_main_window.style.whiteSpace = "nowrap";
		slider_main_window.style.width=parseInt(image_width)+12+'px';
		//slider_main_window.style.height=image_height;
		document.body.appendChild(slider_main_window);
//		document.getElementById("slider_main_window").style.top=getElementPosition("main_hover_div").height/3 + "px";
		document.getElementById("slider_main_window").style.top=60 + "px";
//		document.getElementById("slider_main_window").style.left=getElementPosition("main_hover_div").width/3 + "px";
		main_window_position();
		if (window.addEventListener){
			window.addEventListener('resize', main_window_position, true);
		}else if (window.attachEvent){
				window.attachEvent('onresize', main_window_position);
			 }	

		slider_content = "";
		
		



//		slider_content +='<div id="box_main_picture_slide" style="overflow: hidden; margin: 0 5px 0 5px;position: relative;    -moz-user-select: none;  -khtml-user-select: none;  user-select: none;" oncontextmenu="return false;" ondragstart="return false;" ondrag="return false;" ondragend="return false;" ondragenter="return false" ondragover="return false">';
		slider_content +='<img src="'+path_to_icons+'img/close.gif" style="position:absolute; top:-12px; left:-12px; width:24px; height:24px; cursor:pointer; z-index:1000;" onclick="closeSlider()"><div id="box_main_picture_slide" style="overflow: hidden; margin: 0px 5px 0 5px;position: relative; width:'+image_width+'; height:'+image_height+';" onmouseout="check_mouse_range();">';
		
		
		slider_content += '<img src="'+ big_pictures_dir + big_pictures_list[0]  + '" id="main_picture_slide" onload="correct_slider_big_pic();" style="z-index: 10; width:'+image_width+'; height:'+image_height+';" onmouseup="main_picture_clk();" onmousedown="main_picture_clk();" onmousemove="main_picture_moving(event);">';
		
		slider_content +='<div style="display: block; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; z-index: 15;opacity:0.0; -moz-opacity:0.0; -khtml-opacity:0.0; filter:alpha(opacity=0); background-color: #FFFFFF; " id="main_picture_slide_hover" onmouseup="main_picture_clk();" onmousedown="main_picture_clk(event);" onmousemove="main_picture_moving(event);"></div>';
		slider_content +='</div>';		
		slider_content +='<div style="display:none;position: absolute; top: 12px; left: 0px; width: 19px; z-index: 20;" id="zoomers_panel"><div style="background: url('+path_to_icons+'img/zoom/zoom_in.gif); width: 19px; height:20px; cursor: pointer;" onclick="change_main_picture_size(1);"></div><div style="background: url('+path_to_icons+'img/zoom/zoom_out.gif); width: 19px; height:20px; cursor: pointer;margin-top: 5px;" onclick="change_main_picture_size(2);"></div></div>';







		
		slider_content +='<div style="white-space: nowrap;"><div style="height:60px; width: 9px; float: left; padding:5px 0px 5px 10px; background: url(\''+path_to_icons+'img/scroll_left.jpg\') center center no-repeat;cursor: pointer;" onmouseover="window_icon_list_scroll_left();" onmouseout="window_icon_list_scroll_stop();"></div>';
	
		slider_content +='<div id="slider_main_window_ico_list" style="overflow: hidden; height: 60px; margin: 5px; text-align: center; float: left; white-space: nowrap; width: 690px;">';
		for(i=0;i<small_pictures_list.length;i++){
			slider_content +='<img src="'+small_pictures_dir + small_pictures_list[i]+'" id="'+big_pictures_list[i]+'" style="margin: 0px 5px 0px 5px;width: 90px; height: 60px;cursor: pointer;" onclick="change_main_picture_slide(this.id);">';
		}

		slider_content +='</div><div style="height:60px; width: 9px; float: left; padding:5px 10px 5px 0px; background: url(\''+path_to_icons+'img/scroll_right.jpg\') center center no-repeat;cursor: pointer;" onmouseover="window_icon_list_scroll_right();" onmouseout="window_icon_list_scroll_stop();"></div><div style="height: 0px; line-height: 0px; clear: both;"></div><img src="'+path_to_icons+'img/loader.gif" style="position:absolute; top:45%; left:40%; border:0px; width:220px; height:19px; display:none;" id="lightbox_loader"></div>';
		document.getElementById("slider_main_window").innerHTML = slider_content;

//alert(document.getElementById("slider_main_window").innerHTML);
			
}
function defPosition(event) {
    var x = y = 0;
    if (document.attachEvent != null) { // Internet Explorer & Opera
        x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
        y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
    }
    if (!document.attachEvent && document.addEventListener) { // Gecko
        x = event.clientX + window.scrollX;
        y = event.clientY + window.scrollY;
    }
    return {x:x, y:y};
}

function main_window_position(){
	if (document.getElementById("slider_main_window")){		
		if (((parseInt(document.getElementById("control_hover_div").offsetWidth) - Math.ceil(parseInt(image_width) - 12)/2))>5){
		document.getElementById("slider_main_window").style.left = Math.ceil((parseInt(document.getElementById("control_hover_div").offsetWidth) - parseInt(image_width) - 12)/2) + "px";
		}	
		else {
			document.getElementById("slider_main_window").style.left = '5px';
		}	
		document.getElementById("control_hover_div").style.width ='100%';	
		if ((parseInt(document.documentElement.scrollWidth)-5000)<0){
			document.getElementById("main_hover_div").style.width = document.documentElement.scrollWidth +'px';
		}
		else {
			document.getElementById("main_hover_div").style.width = parseInt(document.documentElement.scrollWidth)-5000+'px';
		}
	//alert(document.body.scrollWidth+' '+document.body.offsetWidth+' '+getElementPosition("control_hover_div").width+' '+document.documentElement.scrollWidth+' '+document.documentElement.offsetWidth)
	}
}

function main_picture_moving(e){
if(main_picture_press == 1){
	if (window.getSelection) { 
		window.getSelection().removeAllRanges(); 
	}
     else {if (document.selection && document.selection.clear) document.selection.clear();
     }
     result = defPosition(e);
     if(result.x > first_x){
  //   	alert(result.x + "   " + first_x);
		document.getElementById("box_main_picture_slide").scrollLeft -= (result.x - first_x)/10;
	}else{
		document.getElementById("box_main_picture_slide").scrollLeft += (first_x - result.x)/10;
	}
	result = defPosition(e);	
     if(result.y > first_y){
		document.getElementById("box_main_picture_slide").scrollTop -= (result.y - first_y)/10;
	}else{
		document.getElementById("box_main_picture_slide").scrollTop += (first_y - result.y)/10;
	}
}
	
}
function main_picture_clk(e){
	if(main_picture_press == 0){
		main_picture_press = 1;
		document.getElementById("main_picture_slide_hover").style.cursor = "url("+path_to_icons+"img/cur/closedhand.cur),url("+path_to_icons+"img/cur/closedhand.gif), url("+path_to_icons+"img/cur/closedhand.png), pointer";		
		result = defPosition(e);
		first_x = result.x;
		first_y = result.y;		
	} else{
		main_picture_press = 0;
		document.getElementById("main_picture_slide_hover").style.cursor = "url("+path_to_icons+"img/cur/openhand.cur),url("+path_to_icons+"img/cur/openhand.gif), url("+path_to_icons+"img/cur/openhand.png), pointer";
	}
}
function check_mouse_range(){
		if(main_picture_press == 1){
		main_picture_press = 0;
		document.getElementById("main_picture_slide_hover").style.cursor = "url("+path_to_icons+"img/cur/openhand.cur),url("+path_to_icons+"img/cur/openhand.gif), url("+path_to_icons+"img/cur/openhand.png), pointer";		
		}
}
function correct_slider_big_pic(){
	if(first_time_show == 0){
		document.getElementById("slider_main_window").style.display="inline"; 
		document.getElementById("slider_main_window_ico_list").style.width = (document.getElementById("main_picture_slide").offsetWidth-38) + "px";
		document.getElementById("box_main_picture_slide").style.width = document.getElementById("main_picture_slide").offsetWidth + "px";
		document.getElementById("box_main_picture_slide").style.height = document.getElementById("main_picture_slide").offsetHeight + "px";
		document.getElementById("main_picture_slide_hover").style.cursor = "url("+path_to_icons+"img/cur/openhand.cur),url("+path_to_icons+"img/cur/openhand.gif), url("+path_to_icons+"img/cur/openhand.png), pointer";
		document.getElementById("zoomers_panel").style.left = (document.getElementById("main_picture_slide").offsetWidth - 19) + "px";
		document.getElementById("zoomers_panel").style.display = "inline";
		first_time_show = 1;
	}
	else {
		document.getElementById("box_main_picture_slide").style.width=image_width;
		document.getElementById("box_main_picture_slide").style.height=image_height;
		document.getElementById("box_main_picture_slide").scrollLeft =0;
		document.getElementById("box_main_picture_slide").scrollTop =0;
		document.getElementById("main_picture_slide").style.width=image_width;
		document.getElementById("main_picture_slide").style.height=image_height;
		
		document.getElementById("main_picture_slide_hover").style.width = (document.getElementById("main_picture_slide").offsetWidth) + "px";
		document.getElementById("main_picture_slide_hover").style.height = (document.getElementById("main_picture_slide").offsetHeight) + "px";	
		
		main_picture_zoom_step=1;	
		document.getElementById("lightbox_loader").style.display="none";	
	}		
}


function  change_main_picture_size(action){
	if(action == 1 && main_picture_zoom_step <= main_picture_zoom){		
		document.getElementById("main_picture_slide").style.width = (document.getElementById("main_picture_slide").offsetWidth * 1.2) + "px";
		document.getElementById("main_picture_slide_hover").style.width = (document.getElementById("main_picture_slide").offsetWidth) + "px";		
		document.getElementById("box_main_picture_slide").scrollLeft=( parseInt(document.getElementById("main_picture_slide").style.width)-parseInt(document.getElementById("box_main_picture_slide").offsetWidth))/2;
		document.getElementById("main_picture_slide").style.height = (document.getElementById("main_picture_slide").offsetHeight * 1.2) + "px";		
		document.getElementById("main_picture_slide_hover").style.height = (document.getElementById("main_picture_slide").offsetHeight) + "px";
		document.getElementById("box_main_picture_slide").scrollTop= ( parseInt(document.getElementById("main_picture_slide").style.height)-parseInt(document.getElementById("box_main_picture_slide").offsetHeight))/2;
		main_picture_zoom_step += 1;
	}
	if(action == 2 && main_picture_zoom_step > 1){
		document.getElementById("main_picture_slide").style.width = (document.getElementById("main_picture_slide").offsetWidth / 1.2) + "px";
		document.getElementById("main_picture_slide_hover").style.width = (document.getElementById("main_picture_slide").offsetWidth) + "px";
		
		document.getElementById("box_main_picture_slide").scrollLeft=( parseInt(document.getElementById("main_picture_slide").style.width)-parseInt(document.getElementById("box_main_picture_slide").offsetWidth))/2;
		document.getElementById("main_picture_slide").style.height = (document.getElementById("main_picture_slide").offsetHeight / 1.2) + "px";		
		
		document.getElementById("main_picture_slide_hover").style.height = (document.getElementById("main_picture_slide").offsetHeight) + "px";		
		document.getElementById("box_main_picture_slide").scrollTop= ( parseInt(document.getElementById("main_picture_slide").style.height)-parseInt(document.getElementById("box_main_picture_slide").offsetHeight))/2;
		main_picture_zoom_step -= 1;
		
	}
}

function change_main_picture_slide(picture_id){
	rndNum = Math.random();
	rndNum = rndNum * 100;
	document.getElementById("lightbox_loader").style.display="inline";	
	/*document.getElementById("box_main_picture_slide").style.width=image_width;
	document.getElementById("box_main_picture_slide").style.height=image_height;
	document.getElementById("box_main_picture_slide").scrollLeft =0;
	document.getElementById("box_main_picture_slide").scrollTop =0;
	document.getElementById("main_picture_slide").style.width=image_width;
	document.getElementById("main_picture_slide").style.height=image_height;*/
	//main_picture_zoom_step=1;	
	document.getElementById("main_picture_slide").src = big_pictures_dir + picture_id +"?id="+Math.round(rndNum);	
}


function slide_scroll_action(step,direction){
	if(direction == 2){
		document.getElementById("slider_main_window_ico_list").scrollLeft += step;
	}
	if(direction == 1){
		document.getElementById("slider_main_window_ico_list").scrollLeft -= step;
	}
}
function window_icon_list_scroll_right(){
	slider_param = "slide_scroll_action("+slider_step+",2)";
	ico_slider_interval = setInterval(slider_param,slider_time_out);
}
function window_icon_list_scroll_left(){
	slider_param = "slide_scroll_action("+slider_step+",1)";
	ico_slider_interval = setInterval(slider_param,slider_time_out);
}
function window_icon_list_scroll_stop(){
	clearInterval(ico_slider_interval);
}
