img_load=new Image();
img_loadf=new Image();
img_loadb=new Image();
scroll_left='';
slider_showonce=false;
last_page='';
var my_t;
//
function next_photo()
{
  if (ipad || iphone)
   {
show_picture('+1');
pos_white_line('photon_'+slide_last)
   }
   else
   {
$('#photo').hide();$('#fullscreen').show(300);
show_picture(slide_last);
   }
}
function i_load()
{
set_events();
 if (chrom || safar) 
 {
 document.getElementById('main_menu').style.lineHeight='19px';
$('.menu_parent').css({lineHeight:'23px',margx7op:'0px',marginBottom:'2px'});
$('#gallery_menu').css({lineHeight:'22px'});
 }
i_resize(); 
}
function i_resize()
{
var client_width=parseInt(document.body.clientWidth);
var client_height=parseInt(document.body.clientHeight);
mw=1614;
mh=416;
if (document.getElementById('main_page'))
{
 if ((client_height-(client_width/mw)*mh)/2>180)
document.getElementById('main_page').style.top=(client_height-(client_width/mw)*mh)/2+'px';
 else document.getElementById('main_page').style.top='180px';
}
// if (document.getElementById('gallery_page'))
document.getElementById('gallery_page').style.height=client_height-180-200+53+'px';
document.getElementById('slider').style.width=client_width-53*2+'px';
document.getElementById('slider').style.top=client_height-180-20-13+19+'px';
document.getElementById('zoomim').style.top=169+11+'px';
document.getElementById('zoomim').style.left=client_width-110+'px';
//16.06.2011 fullscreen
document.getElementById('fs_arrowl').style.top=(client_height-19)/2+'px';
document.getElementById('fs_arrowr').style.top=(client_height-19)/2+'px';
document.getElementById('fs_arrowr').style.left=(client_width-23-20)+'px';
document.getElementById('fs_close').style.top=(client_height-20-24)+'px';
document.getElementById('fs_close').style.left=(client_width-24-20)+'px';

//
  if (navigator.userAgent.indexOf('iPad')!=-1 || navigator.userAgent.indexOf('iPhone')!=-1)
  {
document.getElementById('main_menu').style.top=20+'px';
document.getElementById('main_menu').style.top=20+'px';
document.getElementById('logo_ihouse').style.top=21+'px';
document.getElementById('logo_ihouse').style.display='';
document.getElementById('gallery_menu').style.top=168+'px';
document.getElementById('gallery_page').style.top=150+'px';
document.getElementById('gallery_page').style.height=client_height-30-200+'px';
document.getElementById('slider').style.width=client_width-53*2+'px';
document.getElementById('slider').style.top=client_height-130+'px';
document.getElementById('bio_table').style.marginLeft=251+'px';
document.getElementById('main_menu').style.lineHeight='28px';
  }
 if (last_page=='gallery_page' && slide_last!='') show_picture(slide_last);
document.getElementById('logo_ihouse').style.left=client_width-152+'px';
document.getElementById('logo_ihouse').style.display='block';
}
function set_events()
{
 
  
$('.menu_item').bind('mouseover',function(){
 $(this).addClass("menu_item_over");
  if (chrom || safar) $('.menu_item_over').css({backgroundPosition:'0px 2px'});
 }); 
$('.menu_item').bind('mouseout',function(){
 $(this).removeClass("menu_item_over");
 });
$('.gallery_item').bind('mouseover',function(){
 $(this).addClass("gallery_item_over");
 
 }); 
$('.gallery_item').bind('mouseout',function(){
 $(this).removeClass("gallery_item_over");
 });
$('.gallery_sub').bind('mouseover',function(){
 $(this).addClass("gallery_sub_over");
  if (chrom || safar) $('.gallery_sub_over').css({backgroundPosition:'0px 1px'});
 }); 
$('.gallery_sub').bind('mouseout',function(){
 $(this).removeClass("gallery_sub_over");
 });
 
$(".menu_item").click(function() {
var ihave=$(this).hasClass("menu_item_act");
 if (!ihave) 
  {
 $('.menu_item').removeClass("menu_item_act");
 $('.menu_item').removeClass("menu_item_over");
 $(this).addClass("menu_item_act");
 if (chrom || safar) $('.menu_item_act').css({backgroundPosition:'0px 2px'});
 if (ipad || iphone)
  {  
 $('.menu_item_act').css({backgroundImage:'none'});
 $('.menu_item_act').css({backgroundColor:'#000000'});
// $('.menu_item_act').css({backgroundPosition:'0px -7px'}); 
  }
// if (chrom || safar) $('.menu_item_act').css({backgroundPosition:'0px 2px'});
  }
                });
$(".gallery_item").click(function() {
var ihave=$(this).hasClass("gallery_item_act");
 if (!ihave) 
  {
 $('.gallery_item').removeClass("gallery_item_over");
 $('.gallery_item').removeClass("gallery_item_act");
 $('.gallery_sub').removeClass("gallery_sub_act");
 $(this).addClass("gallery_item_act");
 $('.menu_parent').hide(300); 
var ihave=$(this).next().hasClass("menu_parent");
if (ihave) $(this).next().slideToggle(300);
//alert($(this).children().class);
$(this).next().children(':first-child').click();
  }
  else
  {
 $('.gallery_item').removeClass("gallery_item_over");
 $('.gallery_item').removeClass("gallery_item_act");
 $('.gallery_sub').removeClass("gallery_sub_act");
 $('.menu_parent').hide(300);
  }
                });
$(".gallery_sub").click(function() {
var ihave=$(this).hasClass("gallery_sub_act");
 if (!ihave) 
  {
 $('.gallery_sub').removeClass("gallery_sub_act");
 $('.gallery_sub').removeClass("gallery_sub_over");
 $(this).addClass("gallery_sub_act");
 if (chrom || safar) $('.gallery_sub_act').css({backgroundPosition:'0px 1px'});
 if (ipad || iphone) $('.gallery_sub_act').css({backgroundPosition:'0px -7px'});
  }
                });
}
//
function show_page(page,par)
{
last_page=page;
if (page=='main_page') $('.menu_item').removeClass("menu_item_act");
 if (document.getElementById("contact_page").style.display!='none') $("#contact_page").hide();
 if (document.getElementById("bio_page").style.display!='none') $("#bio_page").hide();
 if (document.getElementById("main_page").style.display!='none') $("#main_page").hide();
 if (document.getElementById("gallery_page").style.display!='none') 
 {
 $("#gallery_page").hide();
 $("#gallery_menu").hide(); 
 $("#slider").hide(); 
 $("#photo").hide(); 
 $("#caption_photo").hide(); 
 $("#white_linerb").hide(); 
 $("#white_linelb").hide(); 
 $("#white_linert").hide(); 
 $("#white_linelt").hide(); 
 $("#zoomim").hide(); 
 }
 if (page=='gallery_page')
 {
 $("#zoomim").show(); 
 $("#slider").show(); 
 $("#photo").show(); 
 $("#caption_photo").show();
 $("#white_linerb").show(); 
 $("#white_linelb").show(); 
 $("#white_linert").show(); 
 $("#white_linelt").show(); 
 	if (par!='press')
   $("#gallery_menu").show(); 
 }
$("#"+page).show();
i_resize(); 
}
function return_index(i)
{
if (i==='-1') i=slide_last-1;
if (i==='+1') i=slide_last+1;
if (i<1) i=slide_arr.length-1;
if (i>slide_arr.length-1) i=1;
return i;
}
function show_picture(i,povt)
{ 
  document.getElementById('caption_photo').style.display='none';
i=return_index(i);
slide_last=i;
 
 if (povt && img_load.complete)
 {
  window.clearTimeout(my_t);
  document.getElementById('photo').src=img_load.src;
  img_load=new Image();
  show_picture2(i);
 }
 else
 {
  if (document.getElementById('photo').src.indexOf('loader.gif')==-1)
  {
var client_width=parseInt(document.body.clientWidth);
var client_height=parseInt(document.body.clientHeight);
document.getElementById('photo').style.border='none';
document.getElementById('photo').style.width='16px';
document.getElementById('photo').style.height='16px';
document.getElementById('photo').style.left='50%';
document.getElementById('photo').style.top='50%';
document.getElementById('photo').src='./i/loader.gif';
  //16.06.2011 fullscreen
  if (document.getElementById('fullscreen').style.display=='block')
   {
document.getElementById('fs_image').style.border='none';
document.getElementById('fs_image').style.width='16px';
document.getElementById('fs_image').style.height='16px';
document.getElementById('fs_image').style.left='50%';
document.getElementById('fs_image').style.top='50%';
document.getElementById('fs_image').src='./i/loader.gif';
img_load.src=path_bigphotos+slide_arr[i].pic;
      if (!povt) { img_load.src=path_bigphotos+slide_arr[i].pic; show_picture(i,true); }
      else my_t=window.setTimeout('show_picture('+i+',true)',30);
      return;
   }

img_load.src=path_photos+slide_arr[i].pic;
 }
  if (!povt) { img_load.src=path_photos+slide_arr[i].pic; show_picture(i,true); }
  else my_t=window.setTimeout('show_picture('+i+',true)',30);
      }

}
function pos_white_line(obj)
{
if (!document.getElementById('slider')) return;
var obj2 = document.getElementById(obj);
//$('.over_img').css({borderLeft:'2px solid white',borderRight:'2px solid white'});
//$('#'+obj).css({borderLeft:'12px solid white',borderRight:'12px solid white'});
//$('.over_img').animate({borderLeft:'2px solid white',borderRight:'2px solid white'},300);
/*$('#'+obj).animate({borderLeft:'12px solid white',borderRight:'12px solid white'},300, function()
{
	//left bottom
  document.getElementById('white_linelb').style.left=obj2.offsetLeft+9;
  document.getElementById('white_linelb').style.top=obj2.offsetHeight;
	//left top
  document.getElementById('white_linelt').style.left=obj2.offsetLeft+9;
  document.getElementById('white_linelt').style.top=obj2.offsetHeight-100+9;
	//right bottom
  document.getElementById('white_linerb').style.left=obj2.offsetLeft+obj2.offsetWidth-27;
  document.getElementById('white_linerb').style.top=obj2.offsetHeight+3;
	//right top
  document.getElementById('white_linert').style.left=obj2.offsetLeft+obj2.offsetWidth-27;
  document.getElementById('white_linert').style.top=obj2.offsetHeight-100+9;
});*/
	//left bottom
  document.getElementById('white_linelb').style.left=obj2.offsetLeft+9-6;
  document.getElementById('white_linelb').style.top=obj2.offsetHeight-3;
	//left top
  document.getElementById('white_linelt').style.left=obj2.offsetLeft+9-6;
  document.getElementById('white_linelt').style.top=obj2.offsetHeight-100+9;
	//right bottom
  document.getElementById('white_linerb').style.left=obj2.offsetLeft+obj2.offsetWidth-27+6;
  document.getElementById('white_linerb').style.top=obj2.offsetHeight-3;
	//right top
  document.getElementById('white_linert').style.left=obj2.offsetLeft+obj2.offsetWidth-27+6;
  document.getElementById('white_linert').style.top=obj2.offsetHeight-100+9;
  
  if (navigator.userAgent.indexOf('iPad')!=-1 || navigator.userAgent.indexOf('iPhone')!=-1)
  {
  //left bottom
  document.getElementById('white_linelb').style.left=obj2.offsetLeft+9-parseInt(document.getElementById('touchme').scrollLeft)-6;
  //right bottom
  document.getElementById('white_linerb').style.left=obj2.offsetLeft+obj2.offsetWidth-27-parseInt(document.getElementById('touchme').scrollLeft)+6;
  //left top
  document.getElementById('white_linelt').style.left=obj2.offsetLeft+9-parseInt(document.getElementById('touchme').scrollLeft)-6;
  document.getElementById('white_linelt').style.top=obj2.offsetHeight-50+9;
  //right top
  document.getElementById('white_linert').style.left=obj2.offsetLeft+obj2.offsetWidth-27-parseInt(document.getElementById('touchme').scrollLeft)+6;
  document.getElementById('white_linert').style.top=obj2.offsetHeight-50+9;
  }
 $("#white_linerb").show(); 
 $("#white_linelb").show(); 
 $("#white_linert").show(); 
 $("#white_linelt").show(); 
}
function scroll_me()
{
$(function() {
$("div#makeMeScrollable").smoothDivScroll({ autoScroll: "none", autoScrollDirection: "backandforth", autoScrollStep: 0, autoScrollx7erval: 15, startAtElementId: "startAtMe", visibleHotSpots: "none"});
});
}
function show_picture2(i)
{
var client_width=parseInt(document.body.clientWidth);
var client_height=parseInt(document.body.clientHeight);
//fulscreen
  if (document.getElementById('fullscreen').style.display=='block')
   {
if (slide_arr[i].pic.indexOf('.mp4')==-1) document.getElementById('fs_image').src=path_bigphotos+slide_arr[i].pic;
   }
   else 
if (slide_arr[i].pic.indexOf('.mp4')==-1) document.getElementById('photo').src=path_photos+slide_arr[i].pic;

 /* if (parseInt(slide_arr[i].w)>=parseInt(slide_arr[i].h))
  {
var top_s=180;
var bottom_s=200;
var left_s=278;
var right_s=0;
var my_w=client_width-left_s-right_s;//width of area
var my_h=client_height-top_s-bottom_s;//height of area
 }
 if (parseInt(slide_arr[i].h)>=parseInt(slide_arr[i].w))
  {*/
var top_s=169;
var bottom_s=158;
var left_s=278;
var right_s=0;
var my_w=client_width-left_s-right_s;//width of area
var my_h=client_height-top_s-bottom_s;//height of area
 /* }*/
   if (navigator.userAgent.indexOf('iPad')!=-1 || navigator.userAgent.indexOf('iPhone')!=-1)
    {
var top_s=150;
var bottom_s=80;
var left_s=229;
var right_s=0;
var my_w=client_width-left_s-right_s;//width of area
var my_h=client_height-top_s-bottom_s;//height of area
   	}
   	//fullscreen
  if (document.getElementById('fullscreen').style.display=='block')
   {
var top_s=0;
var bottom_s=0;
var left_s=0;
var right_s=0;
var my_w=client_width-left_s-right_s;//width of area
var my_h=client_height-top_s-bottom_s;//height of area
   }
var coef=1;
 var coef1=my_w/parseInt(slide_arr[i].w);
 var coef2=my_h/parseInt(slide_arr[i].h);
 if (parseInt(slide_arr[i].w)>my_w || parseInt(slide_arr[i].h)>my_h)
 	 if (coef1<1 || coef2<1)
   {
  	 if (coef1<coef2) coef=coef1;
   else       coef=coef2;
   }
  /* else
   {
  	 if (coef1>coef2) coef=coef1;
   else       coef=coef2;
   }*/
//   if (my_w==parseInt(slide_arr[i].w)*coef) 
//fullscreen
  if (document.getElementById('fullscreen').style.display=='block')
   {
var coef=my_h/parseInt(slide_arr[i].h);
var coef2=my_w/parseInt(slide_arr[i].w);
if (coef*parseInt(slide_arr[i].w)>my_w)
{

document.getElementById('fs_image').style.width=parseInt(slide_arr[i].w)*coef2+'px';
document.getElementById('fs_image').style.height=parseInt(slide_arr[i].h)*coef2+'px';
document.getElementById('fs_image').style.left=(client_width-parseInt(slide_arr[i].w)*coef2)/2+'px';
document.getElementById('fs_image').style.top=(client_height-parseInt(slide_arr[i].h)*coef2)/2+'px';;
}
else
{
document.getElementById('fs_image').style.width='auto';
document.getElementById('fs_image').style.height='100%';	
document.getElementById('fs_image').style.left=(client_width-parseInt(slide_arr[i].w)*coef)/2+'px';
document.getElementById('fs_image').style.top='0px';;
}
/*document.getElementById('fs_image').style.width=parseInt(slide_arr[i].w)*coef+'px';
document.getElementById('fs_image').style.height=parseInt(slide_arr[i].h)*coef+'px';*/


$('#fs_image').css({opacity:0})
$('#fs_image').animate({opacity:1},300);
img_loadf=new Image();
img_loadb=new Image();
img_loadf.src=path_bigphotos+slide_arr[return_index('+1')].pic;
img_loadb.src=path_bigphotos+slide_arr[return_index('-1')].pic;
   return;
   }
document.getElementById('photo').style.width=parseInt(slide_arr[i].w)*coef+'px';
document.getElementById('photo').style.height=parseInt(slide_arr[i].h)*coef+'px';
 
document.getElementById('photo').style.left=(client_width-parseInt(document.getElementById('photo').offsetWidth))/2+'px';
   if (navigator.userAgent.indexOf('iPad')==-1 && navigator.userAgent.indexOf('iPhone')==-1)
if (parseInt(document.getElementById('photo').style.left)<278) document.getElementById('photo').style.left='278px';
document.getElementById('photo').style.top=(client_height+top_s-bottom_s)/2-parseInt(document.getElementById('photo').offsetHeight)/2+'px';
 if (slide_arr[i].brd) 
 {
  document.getElementById('photo').style.border='1px solid #e6e6e6';
  document.getElementById('photo').style.width=parseInt(document.getElementById('photo').style.width)-2+'px';
  document.getElementById('photo').style.height=parseInt(document.getElementById('photo').style.height)-2+'px';
 
 }
 else
 {
  document.getElementById('photo').style.border='none';
	 
 }
 /*loading_photo();*/
$('#photo').css({opacity:0})
$('#photo').animate({opacity:1},300);
img_loadf=new Image();
img_loadb=new Image();
img_loadf.src=path_photos+slide_arr[return_index('+1')].pic;
img_loadb.src=path_photos+slide_arr[return_index('-1')].pic;
$("#caption_photo").show();
var capt=''
if (slide_arr[i].c && slide_arr[i].c!='') capt=slide_arr[i].c;
document.getElementById('caption_photo').style.top='194px';
document.getElementById('caption_photo').style.left=parseInt(document.getElementById('photo').style.width)+parseInt(document.getElementById('photo').style.left)+45;
document.getElementById('caption_photo').innerHTML=capt;
}
function set_section(sec)
{
 if (sec)
  {
slide_arr=sec;
images_to_panel(sec);	
  }
}
function images_to_panel(myimages)
{
 if ( !(document.getElementById('slider') && typeof document.getElementById('slider') == 'object') )
 {
 return;	 
 }
path_photos=myimages[0].path_pic;
path_bigphotos=myimages[0].path_bigpic;
path_thumb=myimages[0].path_thumb;
/*now_section=myimages;*/
if (navigator.userAgent.indexOf('iPad')!=-1 || navigator.userAgent.indexOf('iPhone')!=-1)
{
	
var s='<center><div style="height:62px;overflow: scroll;" id="touchme"><img id="white_linelt" src="./i/left_t_corner.gif"><img id="white_linert" src="./i/right_t_corner.gif"><img id="white_linelb" src="./i/left_b_corner.gif"><img id="white_linerb" src="./i/right_b_corner.gif"><nobr>';
$('#slider').css({height:112});
 for (var i=1; i<myimages.length;i++)
  {
var img_show=slide_arr[i].pic;
if (img_show.indexOf('.mp4')>=0) img_show=img_show.replace('.mp4','.jpg');
s+='<img class="over_img" onload="$(this).animate({opacity:1},300);" style="height:50px;width:'+(50/myimages[i].h)*myimages[i].w+'px" id="photon_'+i+'" onclick="pos_white_line(\'photon_'+i+'\');show_picture('+i+')" src="'+path_thumb+img_show+'" />';
  }
document.getElementById('slider').innerHTML=s+'</nobr></div></center>';
window.setTimeout('pos_white_line("photon_1")',250);
show_picture(1);
document.getElementById('touchme').ontouchstart= function(e){
if(e.touches.length == 1)
				{
         var touch = e.touches[0];
         dragging=touch.pageX;
 $("#white_linerb").hide(); 
 $("#white_linelb").hide(); 
 $("#white_linert").hide(); 
 $("#white_linelt").hide(); 
          }
 }
 document.getElementById('touchme').ontouchmove= function(e){
 	 e.preventDefault();
				if(e.touches.length == 1)
				{
         var touch = e.touches[0];
         document.getElementById('touchme').scrollLeft=-(touch.pageX-dragging)+document.getElementById('touchme').scrollLeft;
         dragging=touch.pageX;
				
				}
			} 
			show_picture(1);
			$('.over_img').css({opacity:0});
return;	
}
var s='<center><div id="makeMeScrollable">';
s+='<div class="scrollingHotSpotLeft"></div>';
s+='<div class="scrollingHotSpotRight"></div>';
s+='<div class="scrollWrapper" id="wrapp">';
s+='<div class="scrollableArea"><img id="white_linelt" src="./i/left_t_corner.gif"><img id="white_linert" src="./i/right_t_corner.gif"><img id="white_linelb" src="./i/left_b_corner.gif"><img id="white_linerb" src="./i/right_b_corner.gif"><nobr>';
 for (var i=1; i<myimages.length;i++)
  {
var img_show=slide_arr[i].pic;
if (img_show.indexOf('.mp4')>=0) img_show=img_show.replace('.mp4','.jpg');
if (i==1)               s+='<img onload="$(this).animate({opacity:1},300);" style="height:100px;width:'+(100/myimages[i].h)*myimages[i].w+'px" id="photon_'+i+'" onclick="pos_white_line(\'photon_'+i+'\');show_picture('+i+')" id="startAtMe" class="over_img" src="'+path_thumb+img_show+'" />';
else                 s+='<img onload="$(this).animate({opacity:1},300);" style="height:100px;width:'+(100/myimages[i].h)*myimages[i].w+'px" id="photon_'+i+'" onclick="pos_white_line(\'photon_'+i+'\');show_picture('+i+')" class="over_img" src="'+path_thumb+img_show+'" />';
  }
document.getElementById('slider').innerHTML=s+'</nobr></div></div></div></center>';
 if (document.getElementById('white_linelb'))
  {
	//left bottom
  document.getElementById('white_linelb').style.top='900px';
	//left top
  document.getElementById('white_linelt').style.top='900px';
	//right bottom
  document.getElementById('white_linerb').style.top='900px';
	//right top
  document.getElementById('white_linert').style.top='900px';
  }
window.setTimeout('pos_white_line("photon_1")',300);
if (navigator.userAgent.indexOf('iPad')==-1 && navigator.userAgent.indexOf('iPhone')==-1)
{
$('.over_img').bind('mouseover',function(){
	$('.over_img').css({opacity:1});
 $(this).css({opacity:0.5});
 }); 
$('.over_img').bind('mouseout',function(){
	$('.over_img').css({opacity:1});
 $(this).css({opacity:1});
 }); 
}
show_picture(1);
$('.over_img').css({opacity:0});
 scroll_me(); 
}

  if (navigator.userAgent.indexOf('iPad')!=-1 || navigator.userAgent.indexOf('iPhone')!=-1)
   {
window.onorientationchange = function(){ window.setTimeout('i_resize()',100); };	
   }
//script by ALaKO, 2011
