YAHOO.namespace("slideShow.container");
var slideShowContainer = YAHOO.slideShow.container;
var slideShowSlides = slideShowContainer.slides = [];

function init() {
			
	var viewWidth = (Math.floor(YAHOO.util.Dom.getViewportWidth()/2))-481;
	var slideShowWidth = "963px";
	var slideShowTop = 71;
	var slideShowZIndex = 2;
	var slideShowFade = 0.75;
	
	
	for (var i=0; i<5; i++){
		
		slideShowSlides[i] = new YAHOO.widget.Overlay("slideShowImage_"+i, {
																			  visible:false,
																			  width:slideShowWidth,
																			  zIndex:slideShowZIndex,
																			   xy:[viewWidth,slideShowTop],
																			  effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:slideShowFade} } );
		
		slideShowSlides[i].render("slideShow");
	}
	
	slideShowSlides[0].show();
	
	slideShowContainer.manager = new YAHOO.widget.OverlayManager(); 
	slideShowContainer.manager.register(slideShowSlides);
	slideShowContainer.manager.activeOverlay = 0;
	YAHOO.util.Event.addListener(window, 'resize', resizeSlideShow);
	
	setTimeout("cycleSlideShow();",15000);
	
	 var carousel = new YAHOO.widget.Carousel("ourWork", {
                        animation: { speed: 0.5 },
                        isCircular: true,
                        numVisible: 1
                        
                });
                        
            carousel.render(); // get ready for rendering the widget
            carousel.show();   // display the widget
	
}

function handleFormInstruction(el){
	if (el.value == ""){
			
		if (YAHOO.util.Dom.hasClass(el, 'instr')){
			YAHOO.util.Dom.removeClass(el, 'instr');
			
		}
		else{
			YAHOO.util.Dom.addClass(el, 'instr');
		}
	}
}


function resizeSlideShow(){
	var viewWidth = (YAHOO.util.Dom.getViewportWidth()/2)-481;
	for (var i=0; i<slideShowSlides.length; i++){
		
		slideShowSlides[i].cfg.setProperty("x", viewWidth); 
		slideShowSlides[i].render("slideShow");
	}
}

function cycleSlideShow(){
	slideShowSlides[slideShowContainer.manager.activeOverlay].hide();
	if (slideShowContainer.manager.activeOverlay < (slideShowSlides.length-1)){
		slideShowContainer.manager.activeOverlay = slideShowContainer.manager.activeOverlay+1;
	}else{
		slideShowContainer.manager.activeOverlay = 0;
	}
	slideShowSlides[YAHOO.slideShow.container.manager.activeOverlay].show();
	setTimeout("cycleSlideShow();",15000);
}

YAHOO.util.Event.onDOMReady(init);

YAHOO.util.Event.onContentReady("mainMenu", function () {

	var userAgent = YAHOO.env.ua,
  animation;  // Animation instance
  
  function onSubmenuBeforeShow(p_sType, p_sArgs) {

  	var menuBody,
    currentElement,
    shadow,
    currentList;
                
    if (this.parent) {

        currentElement = this.element;

        shadow = currentElement.lastChild;
        shadow.style.height = "0px";
    
        if (animation && animation.isAnimated()) {
        
            animation.stop();
            animation = null;
        
        }

        menuBody = this.body;

        if (this.parent && 
            !(this.parent instanceof YAHOO.widget.MenuBarItem)) {
      

            if (userAgent.gecko || userAgent.opera) {
            
                menuBody.style.width = menuBody.clientWidth + "px";
            
            }
            
            if (userAgent.ie == 7) {

                currentElement.style.width = currentElement.clientWidth + "px";

            }
        
        }
    
        menuBody.style.overflow = "hidden";

        currentList = menuBody.getElementsByTagName("ul")[0];

        currentList.style.marginTop = ("-" + currentList.offsetHeight + "px");
    
    }

	}

  function onTween(p_sType, p_aArgs, p_shadow) {

      if (this.cfg.getProperty("iframe")) {
      
          this.syncIframe();
  
      }
  
      if (p_shadow) {
  
          p_shadow.style.height = this.element.offsetHeight + "px";
      
      }
  
  }

  function onAnimationComplete(p_sType, p_aArgs, p_shadow) {

      var menuBody = this.body,
          currentList = menuBody.getElementsByTagName("ul")[0];

      if (p_shadow) {
      
          p_shadow.style.height = this.element.offsetHeight + "px";
      
      }
      
      currentList.style.marginTop = "";
      menuBody.style.overflow = "";

      if (this.parent && 
          !(this.parent instanceof YAHOO.widget.MenuBarItem)) {


          if (userAgent.gecko || userAgent.opera) {
          
              menuBody.style.width = "";
          
          }
          
          if (userAgent.ie == 7) {

              this.element.style.width = "";

          }
      
      }
      
  }

  function onSubmenuShow(p_sType, p_sArgs) {

      var currentElement,
          shadow,
          currentList;
  
      if (this.parent) {

          currentElement = this.element;
          shadow = currentElement.lastChild;
          currentList = this.body.getElementsByTagName("ul")[0];

          animation = new YAHOO.util.Anim(currentList, 
              { marginTop: { to: 0 } },
              .5, YAHOO.util.Easing.easeOut);


          animation.onStart.subscribe(function () {

              shadow.style.height = "100%";
          
          });


          animation.animate();

          if (YAHOO.env.userAgent.ie) {
              
              shadow.style.height = currentElement.offsetHeight + "px";

              animation.onTween.subscribe(onTween, shadow, this);

          }

          animation.onComplete.subscribe(onAnimationComplete, shadow, this);
      
      }
  
  }

  var navBar = new YAHOO.widget.MenuBar("mainMenu", { 
                                              autosubmenudisplay: true, 
                                              hidedelay: 750, 
                                              lazyload: true,
                                              zindex: 999 });
  
  navBar.subscribe("beforeShow", onSubmenuBeforeShow);
  navBar.subscribe("show", onSubmenuShow);

  navBar.render();          

});
