var CONTECH = {};
CONTECH.realImgSwap = function() {
 var active = $('#menuReal .active');
 var nextImg = (active.next().length > 0) ? active.next() : $('#menuReal a:first');
 active.fadeOut(function() {
  active.removeClass('active');
  nextImg.fadeIn().addClass('active');
 });
}
CONTECH.prdOne = function() {

 $('#prdCatList1 > li').click(function(event) {
  var sub1 = $('#prodSubCat1');
  var cid = $(this).attr("id");
  sub1.load('sika.php', {cat: cid}, CONTECH.prdTwo);
  sub1.parent(':hidden').animate({width: 'toggle'}, 'slow');
  $(this).siblings().removeClass('sel');
  $(this).addClass('sel');
  return false;
 });
}
CONTECH.prdTwo = function() {
 var slst = $('#prdCatList2');
 if(slst.outerHeight(true) > 432 ) {
  $('#prodSubCat1').height(400).siblings('.catNav').show();;
 }
 else {
  $('#prodSubCat1').height(432).siblings('.catNav').hide();
 }
 $('#prodSubCat2').empty();
 $('#prdCatList2 > li').click(function(event) {
  var sub1 = $('#prodSubCat2');
  var cid = $(this).attr("id");
  sub1.load('sika.php', {sbcat: cid}, CONTECH.prdDet);
  sub1.parent(':hidden').animate({width: 'toggle'}, 'slow');
  $(this).siblings().removeClass('sel');
  $(this).addClass('sel');
  return false;
 });
}
CONTECH.prdDet = function() {
 $('#prdCatList3 > li').click(function(event) {
  var sub1 = $('#prodDet');
  var cid = $(this).attr("id");
  sub1.load('sika.php', {prd: cid});
  if(sub1.is(':hidden')) {
   sub1.animate({width: 'toggle'}, 'slow');
  }
  $(this).siblings().removeClass('sel');
  $(this).addClass('sel');
  return false;
 });
}
CONTECH.prdSanOne = function() {

 $('#prdCatList1 > li').click(function(event) {
  var sub1 = $('#prodSubCat1');
  var cid = $(this).attr("id");
  sub1.load('sanyo.php', {cat: cid}, CONTECH.prdSanTwo);
  //sub1.load('sanyo.php', {cat: cid});
  sub1.parent(':hidden').animate({width: 'toggle'}, 'slow');
  $(this).siblings().removeClass('sel');
  $(this).addClass('sel');
  return false;
 });
}
CONTECH.prdSanTwo = function() {
 var slst = $('#prdCatList2');
 if(slst.outerHeight(true) > 432 ) {
  $('#prodSubCat1').height(400).siblings('.catNav').show();;
 }
 else {
  $('#prodSubCat1').height(432).siblings('.catNav').hide();
 }
 $('#prodSubCat2').empty();
 $('#prdCatList2 > li').click(function(event) {
  var sub1 = $('#prodSubCat2');
  var cid = $(this).attr("id");
  sub1.load('sanyo.php', {sbcat: cid}, CONTECH.prdSanDet);
  sub1.parent(':hidden').animate({width: 'toggle'}, 'slow');
  $(this).siblings().removeClass('sel');
  $(this).addClass('sel');

  if(cid == "ci14") {
   var sub1 = $('#prodDet');
   sub1.load('sanyoelevdim.php');
   if(sub1.is(':hidden')) {
    sub1.animate({width: 'toggle'}, 'slow');
   }
  }
  return false;
 });
}
CONTECH.prdSanDet = function() {
 $('#prdCatList3 > li').click(function(event) {
  var sub1 = $('#prodDet');
  var cid = $(this).attr("id");
  sub1.load('sanyo.php', {prd: cid});
  if(sub1.is(':hidden')) {
   sub1.animate({width: 'toggle'}, 'slow');
  }
  $(this).siblings().removeClass('sel');
  $(this).addClass('sel');
  return false;
 });
 $('#prdCatOpts select').change(function(event) {
  var pid = $('#fpax').val();
  var sid = $('#fspeed').val();
  $('#sanDim').load('sanyoelevdim.php', {pax: pid, spd: sid});
  return false;
 });
}
CONTECH.loadPrjImage = function(prjId) {
 $.ajax({url: 'prjimg.php',
  data: {id: prjId},
  dataType: 'json',
  type: 'post',
  success: function(j) {
   $('.dynImg').remove();
   if(j.ok === true) {
    CONTECH.dispPrjImage(j.data);
   }
   else {
    $('#prjImg > img').fadeIn();
   }
  }
 });
}
CONTECH.dispPrjImage = function(fname) {
 var img = new Image();
 $('#imgLoadDiv').show();
 $(img).load(function() {
  $(this).hide();
  $('#prjImg').append(this);
  $('#imgLoadDiv').hide();
  $('#prjImg > img').fadeOut();
  $(this).addClass('dynImg').fadeIn(); 
 }).attr('src', './photos/projects/'+fname);
 return;
}
CONTECH.setPrjGal = function() {
 $('#prjImgNav li a').click(function(event) {
  var imgFile = this.href.split('/').pop();
  CONTECH.dispPrjImage(imgFile);
  return false;
 });
 var nav = $('#prjImgNav');
// if(nav.is(':visible')) {
  nav.slideToggle('slow').delay(800).slideToggle('slow');
 //}
 //$('#prjImgNav').animate({height: '0px'}, 'slow');
}
CONTECH.dispRealImage = function(fname) {
 var img = new Image();
 $('#imgLoadDiv').show();
 $(img).load(function() {
  $(this).hide();
  $('#realDet3').append(this);
  $('#imgLoadDiv').hide();
  $('#realDet3 > img').fadeOut();
  $(this).addClass('dynImg').fadeIn(); 
 }).attr('src', './photos/real/'+fname);
 return;
}
$(function(){
 $('#servMain').pngFix();
 setInterval('CONTECH.realImgSwap()', 5000);
 $('#realThumbCont, #aboutMain').jScrollPane({scrollbarWidth: 4, scrollbarMargin: 2, reinitialiseOnImageLoad: true});
 $('#constrList  li').click(function(event) {
      if(this == event.target) {
       var selId = $(this).attr("id");
       $(this).siblings().removeClass('selected').children().slideUp('slow');
       $(this).toggleClass('selected').children().slideToggle('slow');
       return false;
      }
      return true;
    }).children().hide();
 
 $('#constrList > li > ul > li').click(function(event) {
   var selId = $(this).attr("id");
   var pnl = $('#prjDet');
   pnl.load('constrdet.php', {id: selId}); 
   CONTECH.loadPrjImage(selId);
   $('#prjImgNav').load('prjimgthumbs.php', {id: selId}, CONTECH.setPrjGal);
   $('#constrList > li > ul > li').removeClass('selPrj');
   $(this).addClass('selPrj');
  });
 $('#prjImgNavCont').hoverIntent({over:function() {
  $('#prjImgNav').slideToggle('slow');
  },
  timeout: 300,
  out: function() {
   $('#prjImgNav').slideToggle('slow');
  }
 });
 $('.propBox').hover(function(event) {
   propDet = $(this).children('.propDet');
   if(propDet.is(':hidden')) {
    propDet.show();  
   }
  },
  function(event) {
   propDet = $(this).children('.propDet');
   if(propDet.is(':visible')) {
    propDet.hide();  
   }
  });
 $('#realThumbCont ul li a').click(function(event) {
  var imgFile = this.href.split('/').pop();
  CONTECH.dispRealImage(imgFile);
  return false;
 });
 $('#aboutMenu > ul > li > a').click(function(event) {
   var selId = $(this).attr("id");
   var pnl = $('#aboutTop');
   pnl.load('aboutdet.php', {id: selId}, function() {
    $('#aboutMain').jScrollPane({scrollbarWidth: 4, scrollbarMargin: 2, reinitialiseOnImageLoad: true});
   }); 
   if(selId == 'abt1') {
    $('#aboutBtm').show();
   }
   else {
    $('#aboutBtm').hide();
   }
   $('#aboutMenu > ul > li > a').removeClass('sel');
   $(this).addClass('sel');
   return false;
  });
/* $('#aboutBtm ul li').hoverIntent({over:function() {
   $(this).children().filter('.slogPnl').show('slow');
  },
  timeout: 300,
  out: function() {
   $(this).children().filter('.slogPnl').hide('slow');
  }
 });
*/
 $('#brnSika').click(function(event) {
  $('#brnSika').css({'background-position': '-56px 0px'});
  $('#brnSanyo').css({'background-position': '0px 0px'});
  $('#prodMainCat').load('sika.php', {cat: 'ci0'}, CONTECH.prdOne);
  $('#prodMainCat').parent(':hidden').animate({width: 'toggle'}, 'slow');
  $('#prodSubCat1').parent(':visible').animate({width: 'toggle'}, 'slow');
  $('#prodSubCat2').parent(':visible').animate({width: 'toggle'}, 'slow');
  $('.catNav').hide();
  $('#prodDet:visible').animate({width: 'toggle'}, 'slow');
  $(this).addClass('sel');
  return false;
 });
 $('#brnSanyo').click(function(event) {
  $('#brnSanyo').css({'background-position': '-56px 0px'});
  $('#brnSika').css({'background-position': '0px 0px'});
  $('#prodMainCat').load('sanyo.php', {cat: 'ci0'}, CONTECH.prdSanOne);
  $('#prodMainCat').parent(':hidden').animate({width: 'toggle'}, 'slow');
  $('#prodSubCat1').parent(':visible').animate({width: 'toggle'}, 'slow');
  $('#prodSubCat2').parent(':visible').animate({width: 'toggle'}, 'slow');
  $('.catNav').hide();
  $('#prodDet:visible').animate({width: 'toggle'}, 'slow');
  $(this).addClass('sel');
  return false;
 });
 $('.cNvDown').hoverIntent({over:function() {
   var t = $(this).parent().siblings('.prodCat').children('ul');
   var pos = 400 - t.outerHeight(true);
   if(pos < 0) {
    t.animate({top: pos}, 3000);
   }
  },
  timeout: 100,
  out: function() {
   $(this).parent().siblings('.prodCat').children('ul').stop(true, false);
  }
 });
 $('.cNvUp').hoverIntent({over:function() {
   var t = $(this).parent().siblings('.prodCat').children('ul');
   t.animate({top: 0}, 3000);
  },
  timeout: 100,
  out: function() {
   $(this).parent().siblings('.prodCat').children('ul').stop(true, false);
  }
 });
 $('#loading').ajaxStart(function() {
   $(this).show();
  });
 $('#loading').ajaxStop(function() {
   $(this).hide();
  });
 $('#rlNvSrch').click(function(event) {
  $('#realSrch').slideToggle('slow');
  return false;
 });
 $('#realEnq').click(function(event) {
  $('#realEnqBox').slideToggle('slow');
  return false;
 });
 $('#prdShop').click(function(event) {
  $('#prdShopDet').slideToggle('slow');
  return false;
 });
});

