(function($) {
	var imgList = [];
	$.extend({
		preload: function(imgArr, option) {//alert(imgArr[0].src);
			var setting = $.extend({
				init: function(loaded, total) {},
				loaded: function(img, loaded, total) {},
				loaded_all: function(loaded, total) {}
			}, option);
			var total = imgArr.length;
			var loaded = 0;
			
			setting.init(0, total);
			for(var i in imgArr) {
				imgList.push($("<img />")
					.attr("src", 'siteimages/'+imgArr[i].src)
					.load(function() {
						loaded++;
						setting.loaded(this, loaded, total);
						if(loaded == total-1) {//if(loaded == 4 || loaded == total-1) {
							setting.loaded_all(loaded, total);
						}
					})
				);
			}
			
		}
	});
})(jQuery);

  Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
 }
//var varload = 4

// $(function() {
//     // Start showing the divs
//     showDiv();
// });
// 
// function showDiv() {
//     // If there are hidden divs left
//     if($('div:hidden').length) {
//         // Fade the first of them in
//         $('div:hidden:first').fadeIn();
//         // And wait one second before fading in the next one
//         setTimeout(showDiv, 500);
//     }
// }
function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {//alert(obj.offsetLeft)
      curleft += obj.offsetLeft;
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
    curleft += obj.x;
  return curleft;
}
function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  }
  else if (obj.y)
    curtop += obj.y;
  return curtop;
}
var headX = 0;
$(document).ready(function(){
var offsetobj =  $('#header').offset();
headX = offsetobj.left;
  //loop(0, new Image());//abc();
$('#bar1').animate({marginLeft: 0,width: "100%"},1000);
$( "#block1" ).animate({ width: "100%" }, 3000 )
//$( "#bar2" ).animate({ width: "110%" }, 1000 )
$( "#bar2" ).animate({ width: "110%" }, {duration:1000, complete: function() {	$.preload(imagarallarr, {
		init: function(loaded, total) {
			//$("#indicator").html("Loaded: "+loaded+"/"+total);
		},
		loaded: function(img, loaded, total) {
// 			$("#indicator").html("Loaded: "+loaded+"/"+total);
// 			$("#full-screen").append(img);
		},
		loaded_all: function(loaded, total) {
		//setTimeout('abc()',2000);
		abc();
// 			$("#indicator").html("Loaded: "+loaded+"/"+total+". Done!");
		}

	});}} )
$("#content-scroll").animate({"scrollLeft": 500}, 5000);

//   $("#content-slider").slider({
//     animate: true,
//     change: handleSliderChange,
//     slide: handleSliderSlide
//   });
})




var abcdTimeOut;
var abcTimeOut;
var slider_on =1;
var mainwidth = 856;
var imgkey = 0;
// var imagarallarr = [
  // { src: 'homeleft1.jpg', dir: 'left',  width:239},
  // { src: 'homeright1.jpg', dir: 'right',  width:598},
  // { src: 'homeleft2.jpg', dir: 'left',  width:239},
  // { src: 'homeright2.jpg', dir: 'right',  width:598},
  // { src: 'homeleft3.jpg', dir: 'left',  width:239},
  // { src: 'homeright3.jpg', dir: 'right',  width:598},
  // { src: 'homeleft4.jpg', dir: 'left',  width:239},
  // { src: 'homeright4.jpg', dir: 'right',  width:598},
  // { src: 'homeleft5.jpg', dir: 'left',  width:239},
  // { src: 'homeright5.jpg', dir: 'right',  width:598},
  // { src: 'homeleft6.jpg', dir: 'left',  width:239},
  // { src: 'homeright6.jpg', dir: 'right',  width:598},
  // { src: 'homeleft7.jpg', dir: 'left',  width:239},
  // { src: 'homeright7.jpg', dir: 'right',  width:598},
  // { src: 'homeleft8.jpg', dir: 'left',  width:239},
  // { src: 'homeright8.jpg', dir: 'right',  width:598}
// ];
var imagarallarr = [
  { src: 'home/homeleft1.jpg', dir: 'left',  width:239},
  { src: 'home/homeright1.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft2.jpg', dir: 'left',  width:239},
  { src: 'home/homeright2.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft3.jpg', dir: 'left',  width:239},
  { src: 'home/homeright3.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft4.jpg', dir: 'left',  width:239},
  { src: 'home/homeright4.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft5.jpg', dir: 'left',  width:239},
  { src: 'home/homeright5.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft6.jpg', dir: 'left',  width:239},
  { src: 'home/homeright6.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft7.jpg', dir: 'left',  width:239},
  { src: 'home/homeright7.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft8.jpg', dir: 'left',  width:239},
  { src: 'home/homeright8.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft9.jpg', dir: 'left',  width:239},
  { src: 'home/homeright9.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft10.jpg', dir: 'left',  width:239},
  { src: 'home/homeright10.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft11.jpg', dir: 'left',  width:239},
  { src: 'home/homeright11.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft12.jpg', dir: 'left',  width:239},
  { src: 'home/homeright12.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft13.jpg', dir: 'left',  width:239},
  { src: 'home/homeright13.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft14.jpg', dir: 'left',  width:239},
  { src: 'home/homeright14.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft15.jpg', dir: 'left',  width:239},
  { src: 'home/homeright15.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft16.jpg', dir: 'left',  width:239},
  { src: 'home/homeright16.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft17.jpg', dir: 'left',  width:239},
  { src: 'home/homeright17.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft18.jpg', dir: 'left',  width:239},
  { src: 'home/homeright18.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft19.jpg', dir: 'left',  width:239},
  { src: 'home/homeright19.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft20.jpg', dir: 'left',  width:239},
  { src: 'home/homeright20.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft21.jpg', dir: 'left',  width:239},
  { src: 'home/homeright21.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft22.jpg', dir: 'left',  width:239},
  { src: 'home/homeright22.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft23.jpg', dir: 'left',  width:239},
  { src: 'home/homeright23.jpg', dir: 'right',  width:598},
  { src: 'home/homeleft24.jpg', dir: 'left',  width:239},
  { src: 'home/homeright24.jpg', dir: 'right',  width:598}
];
//var imagarright = new Array('gr11.png','gr22.png')
// var planright = [
  // { src: 'homeleft1.jpg', dir: 'left',  width:239},
  // { src: 'homeleft2.jpg', dir: 'left',  width:239},
  // { src: 'homeleft3.jpg', dir: 'left',  width:239},
  // { src: 'homeleft4.jpg', dir: 'left',  width:239},
  // { src: 'homeleft5.jpg', dir: 'left',  width:239},
  // { src: 'homeleft6.jpg', dir: 'left',  width:239},
  // { src: 'homeleft7.jpg', dir: 'left',  width:239},
  // { src: 'homeleft8.jpg', dir: 'left',  width:239}
// ];
var planright = [
  { src: 'homeleft1.jpg', dir: 'left',  width:239},
  { src: 'homeleft2.jpg', dir: 'left',  width:239},
  { src: 'homeleft3.jpg', dir: 'left',  width:239},
  { src: 'homeleft4.jpg', dir: 'left',  width:239},
  { src: 'homeleft5.jpg', dir: 'left',  width:239},
  { src: 'homeleft6.jpg', dir: 'left',  width:239},
  { src: 'homeleft7.jpg', dir: 'left',  width:239},
  { src: 'homeleft8.jpg', dir: 'left',  width:239},
  { src: 'homeleft9.jpg', dir: 'left',  width:239},
  { src: 'homeleft10.jpg', dir: 'left',  width:239},
  { src: 'homeleft11.jpg', dir: 'left',  width:239},
  { src: 'homeleft12.jpg', dir: 'left',  width:239},
  { src: 'homeleft13.jpg', dir: 'left',  width:239},
  { src: 'homeleft14.jpg', dir: 'left',  width:239},
  { src: 'homeleft15.jpg', dir: 'left',  width:239},
  { src: 'homeleft16.jpg', dir: 'left',  width:239},
  { src: 'homeleft17.jpg', dir: 'left',  width:239},
  { src: 'homeleft18.jpg', dir: 'left',  width:239},
  { src: 'homeleft19.jpg', dir: 'left',  width:239},
  { src: 'homeleft20.jpg', dir: 'left',  width:239},
  { src: 'homeleft21.jpg', dir: 'left',  width:239},
  { src: 'homeleft22.jpg', dir: 'left',  width:239},
  { src: 'homeleft23.jpg', dir: 'left',  width:239},
  { src: 'homeleft24.jpg', dir: 'left',  width:239}
];
var planleft = [
  { src: 'homeright1.jpg', dir: 'right',  width:598},
  { src: 'homeright2.jpg', dir: 'right',  width:598},
  { src: 'homeright3.jpg', dir: 'right',  width:598},
  { src: 'homeright4.jpg', dir: 'right',  width:598},
  { src: 'homeright5.jpg', dir: 'right',  width:598},
  { src: 'homeright6.jpg', dir: 'right',  width:598},
  { src: 'homeright7.jpg', dir: 'right',  width:598},
  { src: 'homeright8.jpg', dir: 'right',  width:598},
  { src: 'homeright9.jpg', dir: 'right',  width:598},
  { src: 'homeright10.jpg', dir: 'right',  width:598},
  { src: 'homeright11.jpg', dir: 'right',  width:598},
  { src: 'homeright12.jpg', dir: 'right',  width:598},
  { src: 'homeright13.jpg', dir: 'right',  width:598},
  { src: 'homeright14.jpg', dir: 'right',  width:598},
  { src: 'homeright15.jpg', dir: 'right',  width:598},
  { src: 'homeright16.jpg', dir: 'right',  width:598},
  { src: 'homeright17.jpg', dir: 'right',  width:598},
  { src: 'homeright18.jpg', dir: 'right',  width:598},
  { src: 'homeright19.jpg', dir: 'right',  width:598},
  { src: 'homeright20.jpg', dir: 'right',  width:598},
  { src: 'homeright21.jpg', dir: 'right',  width:598},
  { src: 'homeright22.jpg', dir: 'right',  width:598},
  { src: 'homeright23.jpg', dir: 'right',  width:598},
  { src: 'homeright24.jpg', dir: 'right',  width:598}
];
var n_loaded = 0;
/*function loop(i, img) {
				// this loop is a for (i = 0; i < plan.length; i++)
				// with independent var i, img (for the onload closures)
				img.onload = function(e) {
					n_loaded++;
					planleft[i].width = img.width;
					planleft[i].height = img.height;
					//if (n_loaded == planleft.length)
					//	break;
				}

				img.src = planleft[i].src;
				if (i + 1 < planleft.length) {
					loop(i + 1, new Image());
				} else {
				  setTimeout('abc()',2000);
				}
			}*/
			//loop(0, new Image());
			
// $(function() {
// 	
// 	$.preload(imagarallarr, {
// 		init: function(loaded, total) {
// 			//$("#indicator").html("Loaded: "+loaded+"/"+total);
// 		},
// 		loaded: function(img, loaded, total) {
// // 			$("#indicator").html("Loaded: "+loaded+"/"+total);
// // 			$("#full-screen").append(img);
// 		},
// 		loaded_all: function(loaded, total) {
// 		setTimeout('abc()',2000);
// // 			$("#indicator").html("Loaded: "+loaded+"/"+total+". Done!");
// 		}
// 
// 	});
// 
// });
			
var cnt = planleft.length;
function abc() {
if(slider_on == 0) {
 clearTimeout(abcdTimeOut)
    clearTimeout(abcTimeOut)
	return;
}
//var src1 = imagarleft[imgkey];
//var src2 = imagarright[imgkey];
var src1 = 'siteimages/home/'+planleft[imgkey].src;
var nwidth = planleft[imgkey].width;
var src2 = 'siteimages/home/'+planright[imgkey].src;
imgkey++;
if(imgkey >= cnt) {
imgkey = 0;
}

var blockleft = parseInt(headX)+0;
var block1left = parseInt(headX)+400;
  $("#img1").attr("src",src1);
  $("#img2").attr("src",src2);
  $(".block").css("left",blockleft+"px");
  $(".block1").css("left",block1left+"px");
var newblockleft = mainwidth - nwidth + parseInt(headX);
var newblock1left = parseInt(headX)+0;

  $(".block").animate({"left": newblockleft+"px","opacity":1},{queue:false, duration:1000}, 1000);//1000
  $(".block1").animate({"left": newblock1left+"px","opacity":1},{queue:false, duration:1000}, 1000); //1000
 abcdTimeOut = setTimeout('abcd()',4500); //4500

}

function abcd() {
if(slider_on == 0) {
 clearTimeout(abcdTimeOut)
    clearTimeout(abcTimeOut)
	return;
}
$(".block").animate({"opacity":0})
 $(".block1").animate({"opacity":0})
abcTimeOut = setTimeout('abc()',1000);

}

function stopslide() {//alert('dd');
  if(slider_on == 1) {
    slider_on = 0;
    clearTimeout(abcdTimeOut)
    clearTimeout(abcTimeOut)
    $(".block").animate({"opacity":1})
    $(".block1").animate({"opacity":1})
    $("#stopslideid").css("color","#fe9602");
    $("#playslideid").css("color","#86878a");
  }  
}

function playslide() {
  if(slider_on == 0) {
      slider_on = 1;
    $("#stopslideid").css("color","#86878a");
    $("#playslideid").css("color","#fe9602");  
    abc();
    //loop(0, new Image());
  }
}
var whide = 1;


function work_show() {
if(workalwaysshow == 1) {
  $('#work_sub_menu div').show();
  $('#work_sub_menu1 div').show();
return;	
}
if(whide == 1) {
  $( "#bws" ).fadeIn('slow');
  $('#work_sub_menu div').show("slide", {direction: 'left'},1000);
  $('#work_sub_menu1 div').show("slide", {direction: 'right'},1000);
   whide = 0;
  $('#work_li').addClass("active");
} else {
 work_hide()
}
}

function work_hide() {
if(workalwaysshow == 0) {
 if(whide == 0) {
  $('#work_sub_menu div').hide("slide", {direction: 'left'},1000);
  $('#work_sub_menu1 div').hide("slide", {direction: 'right'},1000);
  $( "#bws" ).fadeOut('slow');
  whide = 1;
 $('#work_li').removeClass("active");
 } 
 }
} 








var abhide = 1;
function about_show() {
if(aboutalwaysshow == 1) {
  $('#about_sub_menu div').show();
  $('#about_sub_menu1 div').show();
return;	
}

if(abhide == 1) {  
  $( "#about_sub" ).fadeIn('slow');
  $('#about_sub_menu div').show("slide", {direction: 'left'},1000);
  $('#about_sub_menu1 div').show("slide", {direction: 'right'},1000);
  $('#about_li').addClass("active");
  abhide = 0;
  } else {
	about_hide() 
  }

}

function about_hide() {
if(aboutalwaysshow == 0) {
 if(abhide == 0) { 
  // $('#about_sub_menu').animate({marginLeft:100,width: 0},1000);
  // $('#about_sub_menu1').animate({marginLeft:100,width: 0},1000);
  $('#about_sub_menu div').hide("slide", {direction: 'left'},1000);
  $('#about_sub_menu1 div').hide("slide", {direction: 'right'},1000);
  $( "#about_sub" ).fadeOut('slow');
  abhide = 1;
  $('#about_li').removeClass("active");
 } 
 }
}

var presshide = 1;
function press_show() {
if(aboutalwaysshow == 1) {
  $('#press_sub_menu div').show();
  $('#press_sub_menu1 div').show();
return;	
}
if(presshide == 1) {  
  $( "#press_sub" ).fadeIn('slow');
  $('#press_sub_menu div').show("slide", {direction: 'left'},1000);
  $('#press_sub_menu1 div').show("slide", {direction: 'right'},1000);
	$('#press_li').addClass("active");
  presshide = 0;
  
  } else {
	press_hide()
  }

}

function press_hide() {
if(pressalwaysshow == 0) {
 if(presshide == 0) { 
  // $('#about_sub_menu').animate({marginLeft:100,width: 0},1000);
  // $('#about_sub_menu1').animate({marginLeft:100,width: 0},1000);
  $('#press_sub_menu div').hide("slide", {direction: 'left'},1000);
  $('#press_sub_menu1 div').hide("slide", {direction: 'right'},1000);
  $( "#press_sub" ).fadeOut('slow');
  presshide = 1;
   $('#press_li').removeClass("active");
 } 
 }
}






allImages = [ 
              [
                { thumb:'thumb_01.jpg',orig: 'orig_01.jpg'},
                { thumb:'thumb_02.jpg',orig: 'orig_02.jpg'},
                { thumb:'thumb_03.jpg',orig: 'orig_03.jpg'},
                { thumb:'thumb_04.jpg',orig: 'orig_04.jpg'},
                { thumb:'thumb_05.jpg',orig: 'orig_05.jpg'},
                { thumb:'thumb_06.jpg',orig: 'orig_06.jpg'},
				{ thumb:'thumb_07.jpg',orig: 'orig_07.jpg'}
              ],
              [
                { thumb:'thumb_01.jpg',orig: 'orig_01.jpg'},
                { thumb:'thumb_02.jpg',orig: 'orig_02.jpg'},
                { thumb:'thumb_03.jpg',orig: 'orig_03.jpg'},
                { thumb:'thumb_04.jpg',orig: 'orig_04.jpg'},
                { thumb:'thumb_05.jpg',orig: 'orig_05.jpg'},
                { thumb:'thumb_06.jpg',orig: 'orig_06.jpg'},
				{ thumb:'thumb_07.jpg',orig: 'orig_07.jpg'},
				{ thumb:'thumb_08.jpg',orig: 'orig_08.jpg'}
              ],
            ];
			
 //var interior_images = [6,5,7,8,8,8,8,6,8,6,5,6,8];	
 var interior_images = [6,5,7,8,8,8,8,7,8,8,8,6,8];	
 
	var ind_glb_slide = 1
	var pic_glb_slide = 1
//alert(allImages[1][1].thumb);

//allImages = [{set:[{ src:'gr_1.png',orig: 'd'}]}];
//alert(allImages[0].set[0].src);

function changeactive(interior_index) {
	var il = interior_images.length
	for(var i = 1; i<=il; i++) {
		$('#entity_'+i).removeClass("active");
	}
	$('#entity_'+interior_index).addClass("active");
}

function change_thumb(thumbindex,flag,thumbselind) {
if(flag == 1 || flag == '1' ) {
if(typeof intSlidePrevimeOut != 'undefined') {
 clearTimeout(intSlidePrevimeOut);
 }
}
if(typeof thumbselind != 'undefined') {
 var newthumbselind = thumbselind;
} else {
 var newthumbselind = 1;
}

//var thumblen = allImages[thumbindex].length;
var interior_index = thumbindex +1;
var thumblen = interior_images[thumbindex];

var thumb_dir_name = 'interiors/interior_'+interior_index+'/thumbnail';
var thumb_sel_dir_name = 'interiors/interior_'+interior_index+'/thumbnail_sel';
var orig_dir_name = 'interiors/interior_'+interior_index+'/big_images';
var inhtml =  '<ul>'
var lastclass = '';
var n_i = 0;
var ext = '.jpg';
changeactive(interior_index);
for(var i = 0;i<thumblen;i++) {
  if(i == 0) {
    lastclass = 'first_thumbnail';
  } else if(i == (thumblen-1)) {
    lastclass = 'last_thumbnail';
  } else {
    lastclass = '';
  }
   n_i = i+1;
  //inhtml +=  '<li><a href="#" class="'+lastclass+'"><img onclick = "change_preview(\''+orig_dir_name+'/'+allImages[thumbindex][i].orig+'\')" src="images/'+thumb_dir_name+'/'+allImages[thumbindex][i].thumb+'" alt="" /></a></li>';
  inhtml +=  '<li><a href="#" class="'+lastclass+'"><img onclick = "change_preview(\''+orig_dir_name+'/orig_0'+n_i+ext+'\','+interior_index+','+n_i+',1)" src="siteimages/'+thumb_dir_name+'/thumb_0'+n_i+ext+'" alt="" id = "thumb_0'+n_i+'"/></a></li>';
}
inhtml +=  '</ul>';

 $("#all_thumb").fadeOut(400, function() { $(this).html(inhtml); }) .delay(400).fadeIn(400);
 var origimg = orig_dir_name+'/orig_0'+newthumbselind+ext;
 change_preview(origimg,interior_index,newthumbselind,0);
}

function change_preview(origimg,interior_index,thumbselindex,flag) { //alert(origimg);
ind_glb_slide =  interior_index;
pic_glb_slide = thumbselindex;
//var origimgtag = '<img  src="images/'+origimg+'" alt=""/>';
if(flag == 1 || flag == '1' ) {
 if(typeof intSlidePrevimeOut != 'undefined') {
 clearTimeout(intSlidePrevimeOut);
 }
}
origimg = 'siteimages/'+origimg;
 change_arrow(interior_index,thumbselindex,flag);
 if (origimg != $('img#largeImg').attr('src').replace(/\?(.*)/,'')) {
            $('img#largeImg').stop().animate({opacity:'0'},function(){
                   // $(this).attr('src',origimg+'?'+Math.floor(Math.random()*(10*100)));
					//alert('his');
					//alert(origimg);
				    $(this).attr('src',origimg);
					change_thumb_sel(interior_index,thumbselindex)
            }).load(function(){
					//alert('hiy');
                    $(this).stop().animate({opacity:'1'});
            });
        } else {
			//alert('hi');
		}


//$("#main_img_div").fadeIn(400, function() { $(this).html(origimgtag); });
  //$("#main_img_div").fadeOut(400, function() { $(this).html(origimgtag); }) .delay(400).fadeIn(400);
}

function change_arrow(interior_index,thumbselindex,flag) {

var orig_dir_name = 'interiors/interior_'+interior_index+'/big_images';
var ext = '.jpg';
var thumblen = interior_images[interior_index -1];
if(thumblen == thumbselindex) {
//interior_index = parseInt(interior_index) + 1;
  if(interior_index == interior_images.length -1) {
	interior_index = 0;
  }	
  var inhtmlnext = '<div onclick = "change_thumb('+interior_index+',1)"><img src = "images/icons/next_icon.jpg" style="margin-top:5px;cursor:pointer;"/></div>';
} else {
  var n_i_next = parseInt(thumbselindex) + 1;
    var inhtmlnext = '<div onclick = "change_preview(\''+orig_dir_name+'/orig_0'+n_i_next+ext+'\','+interior_index+','+n_i_next+',1)"><img src = "images/icons/next_icon.jpg" style="margin-top:5px;cursor:pointer;"/></div>';
}
if(thumbselindex == 1) {
  var interior_index_old = parseInt(interior_index) - 2;
  if(interior_index_old <0) {
	interior_index_old = interior_images.length - 1;
  }
  var thumblenno = interior_images[interior_index_old]
  var inhtmlprev = '<div onclick = "change_thumb('+interior_index_old+',1,'+thumblenno+')"><img src = "images/icons/prev_icon.jpg" style="margin-top:5px;cursor:pointer;"/></div>';
} else {
  var n_i_prev = parseInt(thumbselindex) -1;
  var inhtmlprev = '<div onclick = "change_preview(\''+orig_dir_name+'/orig_0'+n_i_prev+ext+'\','+interior_index+','+n_i_prev+',1)"><img src = "images/icons/prev_icon.jpg" style="margin-top:5px;cursor:pointer;"/></div>';
}
 $('#prevarrow').html(inhtmlprev);
  $('#nextarrow').html(inhtmlnext);
  
  //change_preview(origimg,interior_index,thumbselindex,flag);
}

function change_thumb_sel(interior_index,thumbselindex) {
var thumblen = interior_images[interior_index-1];
var thumb_sel_dir_name = 'interiors/interior_'+interior_index+'/thumbnail_sel';
var thumb_dir_name = 'interiors/interior_'+interior_index+'/thumbnail';
var ext = '.jpg';
for(var i = 0;i<thumblen;i++) {
    var n_i = i+1;
	if(n_i == thumbselindex) {
		var thumbselimg = 'siteimages/'+thumb_sel_dir_name+'/thumb_sel_0'+n_i+ext;
		//alert(thumbselimg)
		//document.getElementById('thumb_0'+n_i).src = thumbselimg;
		$('img#thumb_0'+n_i).attr('src',thumbselimg);
	} else {//alert(n_i);
		var thumbimg = 'siteimages/'+thumb_dir_name+'/thumb_0'+n_i+ext;
		//document.getElementById('thumb_0'+n_i).src = thumbimg;
		$('img#thumb_0'+n_i).attr('src',thumbimg);
	}
}
}

function pic_slideshow(interior_index,pic_index){//alert('i'+interior_index)
var interior_index1 = interior_index+1
		var orig_dir_name = 'interiors/interior_'+interior_index1+'/big_images';
		var thumb_sel_dir_name = 'interiors/interior_'+interior_index1+'/thumbnail_sel';
		var thumblen = interior_images[interior_index];
		var n_i = 0;
		var ext = '.jpg';
		if(pic_index<thumblen ) {
			pic_index++;
			var origimg = orig_dir_name+'/orig_0'+pic_index+ext;
			//alert(origimg);
			var thumbimg = thumb_sel_dir_name+'/thumb_sel_0'+pic_index+ext;
			
			change_preview(origimg,interior_index1,pic_index,0);
			intSlidePrevimeOut = setTimeout('pic_slideshow('+interior_index+','+pic_index+')',4200);
		} else {
			interior_index++;
			pic_index = 0;
			
			if(interior_index <= interior_images.length) {
				change_thumb(interior_index,0);
				pic_slideshow(interior_index,pic_index);
			} else {
				interior_index = 1;
				change_thumb(interior_index,0);
				pic_slideshow(interior_index,pic_index);
			}	
			//interior_slideshow(interior_index);
		}
		//return;
}		

function interior_slideshow(interior_index,pic_index){
$("#stopslideid").css("color","#86878a");
    $("#playslideid").css("color","#fe9602");
	interior_index = ind_glb_slide
	pic_index = pic_glb_slide
	/*alert(interior_index)
	alert(pic_index)*/
//change_thumb(interior_index-1,0);
change_thumb(interior_index-1,pic_index);
pic_slideshow(interior_index -1,pic_index);
		// var orig_dir_name = 'interiors/interior_'+interior_index+'/big_images';
		// var thumblen = interior_images[interior_index];
		// var n_i = 0;
		// var ext = '.jpg';
		// var pic_index =0;
		// if(pic_index<thumblen ) {
			// intSlidePrevimeOut = setTimeout('pic_slideshow('+interior_index+','+pic_index+')',1000);
			
			// pic_index++;
		// }
		// for(var i = 0;i<thumblen;i++) {
			// var n_i = i+1;
			// var origimg = orig_dir_name+'/orig_0'+n_i+ext;
		// //	alert(origimg)
			// intSlidePrevimeOut = setTimeout('change_preview(\''+origimg+'\')',1000);
		// }
		// interior_index++;
		// intSlideTimeOut = setTimeout('interior_slideshow('+interior_index+')',1000);
		
}

function interior_slideshow_stop() {
if(typeof intSlidePrevimeOut != 'undefined') {
	clearTimeout(intSlidePrevimeOut);
 }
 $("#stopslideid").css("color","#fe9602");
 $("#playslideid").css("color","#86878a");
}
allImagesReno = [ 
              [
                { thumb:'thumb1.jpg',origbefore: 'hibefore.jpg',origafter: 'hiafter.jpg'},
                { thumb:'thumb2.jpg',origbefore: 'before1.gif',origafter: 'after1.gif'},
                { thumb:'thumb3.jpg',origbefore: 'hibefore.jpg',origafter: 'hiafter.jpg'},
                { thumb:'thumb4.jpg',origbefore: 'hibefore.jpg',origafter: 'hiafter.jpg'},
                { thumb:'thumb5.jpg',origbefore: 'hibefore.jpg',origafter: 'hiafter.jpg'},
                { thumb:'thumb6.jpg',origbefore: 'hibefore.jpg',origafter: 'hiafter.jpg'}
              ],
              [
                { thumb:'thumb1.jpg',origbefore: 'hibefore.jpg',origafter: 'hiafter.jpg'},
                { thumb:'thumb2.jpg',origbefore: 'hibefore.jpg',origafter: 'hiafter.jpg'},
                { thumb:'thumb3.jpg',origbefore: 'hibefore.jpg',origafter: 'hiafter.jpg'},
                { thumb:'thumb4.jpg',origbefore: 'hibefore.jpg',origafter: 'hiafter.jpg'},
                { thumb:'thumb5.jpg',origbefore: 'hibefore.jpg',origafter: 'hiafter.jpg'},
                { thumb:'thumb6.jpg',origbefore: 'hibefore.jpg',origafter: 'hiafter.jpg'}
              ],
            ];
	    
//var renovation_images = [8,7,7,6,7,7,6,7,7];	
//var allteoimgreno = [[6],[4,5],[1,2,3,4,5,6,7],[2],[5],[3,5,6,7],[5],[2,4],[1,2,9,3,5,6]];	
//var spimgreno = [[100],[1,6,7],[100],[100],[100],[100],[100],[1,5],[100]];	
 var renovation_images = [8,6,7,7,7,7,6,7,7];
 var allteoimgreno = [[6],[2],[4,5],[5],[1,2,3,4,5,6,7],[3,5,6,7],[4],[2,4],[2,3,5,6]];
 var spimgreno = [[100],[100],[1,6,7],[100],[100],[100],[100],[1,5],[100]];
 var colimgreno = [[100],[100],[100],[7],[100],[3],[4],[1,5],[1,7]];
function change_thumb_rennovation(thumbindex) {
var thumblen = renovation_images[thumbindex]//allImagesReno[thumbindex].length;
var inhtml =  '<ul>'
var lastclass = '';
var directory_index = thumbindex+1;
changeactive(directory_index);
var dirimgbefore = 'renovations/renovation_'+directory_index+'/before/';
var dirimgafter = 'renovations/renovation_'+directory_index+'/after/';
var dirimgbefore1= 'renovations/renovation_'+directory_index+'/before_1/';
var thumb_dir_name = 'renovations/renovation_'+directory_index+'/thumbnail/';
var n_i = 0;
var ext = '.jpg'
 var origimgafter = '';
  var origimgbefore = '';
  var origimgbefore1 =  '';
  var objectsar = {};
  var x = 0;
for(var i = 0;i<thumblen;i++) {
  if(i == thumblen) {
    lastclass = 'last_thumbnail';
  } else {
    lastclass = '';
  }
 // inhtml +=  '<li><a href="javascript:void(0)" class="'+lastclass+'"><img onclick = "change_preview_reno(\''+allImagesReno[thumbindex][i].origbefore+'\',\''+allImagesReno[thumbindex][i].origafter+'\')" src="images/'+allImagesReno[thumbindex][i].thumb+'" alt="" /></a></li>';
 
   n_i = i+1;
  origimgafter = dirimgafter+'/after_'+n_i+ext;
  origimgbefore = dirimgbefore+'/before_'+n_i+ext;
  origimgbefore1 = dirimgbefore1+'/before_1_'+n_i+ext;
  objectsar[x++] = {src:origimgafter}
  objectsar[x++] = {src:origimgbefore}
  objectsar[x++] = {src:origimgbefore1}
   inhtml +=  '<li><a href="javascript:void(0)" class="'+lastclass+'"><img onclick = "change_preview_reno(\''+origimgafter+'\',\''+origimgbefore+'\',\''+origimgbefore1+'\','+n_i+','+directory_index+')" src="siteimages/'+thumb_dir_name+'/thumb_'+n_i+ext+'" alt="" id = "thumb_'+n_i+'"/></a></li>';
}
inhtml +=  '</ul>';

/*
  for(var p in objectsar) {
 //var innerObj = objectsar[p];
 document.write('<div>container.' + p + ':' + objectsar[p].src + '</div>');
 }*/

  $("#all_thumb_reno").fadeOut(400, function() { $(this).html(inhtml);change_thumb_sel_reno(directory_index,1); }) .delay(400).fadeIn(400);
  
  var oaft = dirimgafter+'/after_1'+ext;
  var obef =  dirimgbefore+'/before_1'+ext;
  var obef1 = dirimgbefore1+'/before_1_1'+ext;

 change_preview_reno(oaft,obef,obef1,1,directory_index);

   $.preload(objectsar, {
		init: function(loaded, total) {
			//$("#indicator").html("Loaded: "+loaded+"/"+total);
		},
		loaded: function(img, loaded, total) {
// 			$("#indicator").html("Loaded: "+loaded+"/"+total);
// 			$("#full-screen").append(img);
		},
		loaded_all: function(loaded, total) {
		}

	});
}
//var twoimage

function change_preview_reno(origimgafter,origimgbefore,origimgbefore1,imgindex,directory_index) {
  
  var imagforload= [
    { src: origimgafter},
    { src: origimgbefore},
    { src: origimgbefore1}
  ]

  origimgbefore = 'siteimages/'+origimgbefore;
  origimgafter = 'siteimages/'+origimgafter;
  origimgbefore1= 'siteimages/'+origimgbefore1;
  if(spimgreno[directory_index-1].in_array(imgindex)) {
	var issp = 11;
  } else {
	var issp = 0;
  }
  if(colimgreno[directory_index-1].in_array(imgindex)) {
	var iscol = 1;
	if(imgindex == 5) {
		var iscol = 2;
	}
	if(imgindex == 3 || imgindex == 4) {
		var iscol = 3;
	}
	if(directory_index == 9 && imgindex == 1) {
		var iscol = 4;
	}
  } else {
	var iscol = 0;
  }
  
 var lncook = readCookie('ln');
 if(lncook == 'esp') {
		var ln = 'esp';
      var afterText = 'DESPUES';
      var beforeText ='ANTES';
 } else {
		var ln = 'en';
       var afterText = 'AFTER';
      var beforeText ='BEFORE';
 }
 if(allteoimgreno[directory_index-1].in_array(imgindex)) {
var istwoimage = 1;
var inhtml = '<div class="main_banner"  id="container" style="height:528px; padding: 0;"><div><img id = "before_img" alt="before" src="'+origimgbefore+'" 1width="686" 1height="528" /></div>';
    inhtml += '<div><img id = "after_img"  alt="after" src="'+origimgafter+'" 1width="686" 1height="528" /></div></div>';
} else {
var istwoimage = 0;
 var inhtml = '<div class="main_banner"  id="container" style="height:528px; padding: 0;"><div><img id = "before_img" alt="before" src="'+origimgbefore+'" 1width="686" 1height="528" /></div>';
  inhtml += '<div><img id = "before_img1" alt="before" src="'+origimgbefore1+'" 1width="686" 1height="528" /></div>'
  inhtml += '<div><img id = "after_img"  alt="after" src="'+origimgafter+'" 1width="686" 1height="528" /></div></div>';
}
change_thumb_sel_reno(directory_index,imgindex);
  $.preload(imagforload, {
		init: function(loaded, total) {
			//$("#indicator").html("Loaded: "+loaded+"/"+total);
		},
		loaded: function(img, loaded, total) {
// 			$("#indicator").html("Loaded: "+loaded+"/"+total);
// 			$("#full-screen").append(img);
		},
		loaded_all: function(loaded, total) {
      $("#bef_aft_container").html(inhtml);
     //  $("#bef_aft_container").html(inhtml).delay(400).fadeIn(400);
		  $('#container').beforeAfter({
      animateIntro : false,
      introPosition:.85,
      introDuration :2000,
      clickSpeed:2000,
      linkDisplaySpeed:1000,
      defaultgap:100,
      leftgap:100,
      rightgap:100,
      afterLinkText:afterText,
      beforeLinkText:beforeText,
      istwoimage:istwoimage,
	  isspecial:issp,
	  ln:ln,
	  iscol:iscol
      });
		}

	});
}

function change_thumb_sel_reno(directory_index,thumbselindex) {
var thumblen = renovation_images[directory_index-1];
var thumb_sel_dir_name = 'renovations/renovation_'+directory_index+'/thumbnail_sel';
var thumb_dir_name = 'renovations/renovation_'+directory_index+'/thumbnail';
var ext = '.jpg';
for(var i = 0;i<thumblen;i++) {
    var n_i = i+1;
	if(n_i == thumbselindex) {
		var thumbselimg = 'siteimages/'+thumb_sel_dir_name+'/thumb_sel_'+n_i+ext;
		$('img#thumb_'+n_i).attr('src',thumbselimg);
	} else {//alert(n_i);
		var thumbimg = 'siteimages/'+thumb_dir_name+'/thumb_'+n_i+ext;
		$('img#thumb_'+n_i).attr('src',thumbimg);
	}
}
}

function tell_friend(refloc){
		window.open('tell_a_friend.php?refloc='+refloc, 'tellafriend_script','scrollbars=1,statusbar=1,resizable=1,width=480,height=650');
	}
	
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
/*
function twoimgreno(d,t) {
var reflag =false;
if(d == 1) {

} else if(d == 2){
} else if(d == 2){
} else if(d == 2){
} else if(d == 2){
} else if(d == 2){
} else if(d == 2){
} else if(d == 2){
}
 return reflag;
}
*/
//9-1;1-no;2-1,6,7;3-no;4-no;5-no;6-no;7-no;8-1,5
