﻿
var Intech=Intech||{};(function($)
{function Cycle(type)
{var type=type;var idx=0;this.getList=function()
{return Intech.db[type].byPubDate||[];};this.next=function()
{if(++idx>=this.getList().length)idx=0;return this.getList()[idx]};this.prev=function()
{if(--idx<0)idx=this.getList().length-1;return this.getList()[idx];};this.get=function()
{return this.getList()[idx];}}
var WidgetCtrl=function(el,type)
{var self=this;var url=Cuke.format('{0}Intechinfo/Nub/Views/Remote/WidgetWriter.ashx',Cuke.rootUrl);var el=el;var type=type;var cycle=new Cycle(type);var cache={project:[],stats:[],testimonial:[],news:[]};var eNext=$('.i-nav .i-next',el);var ePrev=$('.i-nav .i-prev',el);eNext.click(function(){self.next();});ePrev.click(function(){self.prev();});this.next=function(){self.load(cycle.next());};this.prev=function(){self.load(cycle.prev());};this.load=function(id)
{var c=cache[type][id];if(c)
{self.update(c);}
else
{$.get(url,{type:type,id:id},function(data){cache[type][id]=data;self.update(data);});}};function removeFilterAttr(el)
{if(jQuery.browser.msie){el[0].style.removeAttribute('filter');}}
this.update=function(html){var x=$j('.i-view',el);var h=el.height();el.height(h);x.fadeOut(200,function(){removeFilterAttr(x);x.contents().remove();x.html(html);x.show();x.show();el.animate({height:x.height()});});};}
var initWidgets=function()
{var url="{0}Intechinfo/Nub/Views/Remote/WidgetWriter.ashx";var project=$('.i-widget-project');var stats=$('.i-widget-stats');var tesnimonial=$('.i-widget-testimonial');var news=$('.i-widget-news');var o={project:[],stats:[],testimonial:[],news:[]};project.each(function(){o.project[o.project.length]=new WidgetCtrl($(this),'project');});stats.each(function(){o.stats[o.stats.length]=new WidgetCtrl($(this),'stats');});tesnimonial.each(function(){o.testimonial[o.testimonial.length]=new WidgetCtrl($(this),'testimonial');});news.each(function(){o.news[o.news.length]=new WidgetCtrl($(this),'news');});return o;};var initMainNav=function()
{var overCls='i-mn-item-over';var n=$j('.i-main-nav');if(n.length==0)n=$j('.i-home-nav');n.show();var f=$j('>li',n);var flk=$j('>li>div>a',n);var s=$j('>li>ul>li',n);var slk=$j('>li>ul>li>div>a',n);f.addClass('i-mn-first');flk.addClass('i-lk-first');s.addClass('i-mn-sub');slk.addClass('i-lk-sub');var timeout=0;var last;f.mouseover(function(e)
{var s=$j(this);if(last&&last!=s)last.removeClass(overCls);last=s;clearTimeout(timeout);s.addClass(overCls);});f.mouseout(function(e)
{var s=$j(this);timeout=setTimeout(function()
{s.removeClass(overCls);},100);});$j('>li>ul',n).removeAttr('style');};var initReasons=function()
{var r=$j('.i-reasons');var ctx={desc:null};var currentItem;var isAnimating=false;var inHandler=function(el)
{isAnimating=true;var $this=$j(this);currentItem=$this;var filter=$j(".i-filterLayer",r);filter.removeClass("unActive");filter.addClass("active");filter.css({opacity:0.8});$j(".i-back",$this).fadeOut('fast',function()
{isAnimating=false;});$j(".i-layer",$this).fadeOut('fast');ctx.desc=$j(".i-inner",$this).html();var outer=$j(".i-outer-description");var o=$this.position();var wrap=$j('<div class="i-inner"></div>');wrap.append(ctx.desc).appendTo(outer);$j(".i-description",outer).show();outer.css({left:o.left,top:$this.height()+o.top,width:$this.width()}).fadeIn('fast',function()
{$j('.i-reasons').height(outer.height()+outer.position().top);});$this.css("z-index",1);};var leaveHandler=function(el)
{isAnimating=true;var $this=currentItem;$j(".i-filterLayer",r).removeClass("active").addClass("unActive");$j(".i-back",$this).fadeIn('fast',function()
{isAnimating=false;});$j(".i-layer",$this).fadeIn('fast');$j(".i-inner",$this).empty().append(ctx.desc);$j(".i-outer-description").empty().width(0).hide();$j(".i-description",$this).fadeOut('fast',function()
{$j('.i-reasons').height('auto');$this.css("z-index",0);});};$j(".i-filterLayer").click(leaveHandler);$j(".i-reason-item",r).toggle(inHandler,leaveHandler).hover(function()
{if(!isAnimating){$j(".i-back",this).animate({opacity:1});}},function()
{if(!isAnimating){$j(".i-back",this).animate({opacity:0.8});}});};jQuery(function()
{initMainNav();initWidgets();initReasons();});Intech.db={project:{},testimonial:{},stats:{},news:{}};})(jQuery);
