/*
$(document).ready(function () {

	// detect if user has Skype installed and add proper class to body element

	function updateInstalledClass() {
		$('body').addClass(SkypeDetection.installed ? 'skypeInstalled' : 'skypeNotInstalled');
	}

	if (SkypeDetection) {
		if (SkypeDetection.ready) {
			updateInstalledClass();
		} else {
			SkypeDetection.detect(updateInstalledClass);
		}
	}

	// detect if operating system add proper class to body element

	if (SKYPE.util.Browser) {
		if (SKYPE.util.Browser.isWindows) {
			$('body').addClass("windowsDetected");
		} else if (SKYPE.util.Browser.isMac) {
			$('body').addClass("macosDetected");
		}
	}
});*/

heroNavManager = {

	autoChangeDelay: 5, // auto slide change delay (in seconds)

	init: function (){
        window.addEvent('domready', function()
        {
            $$('div.hero').each(function(item)
            {
                var $hero = item;
                var $slides = $hero.getElements('div.heroSlide');
                var $control = $hero.getElement('div.heroNav');
                var $slideLinks = $control.getElements("a.heroSlideLink");


                //debugger;
                var curSlide = $hero.getElement('div.heroCurrent');
                var index = $slides.indexOf(curSlide);
                  showSlide(index);


                $control.getElements("a").each(function(item) {
                    item.addEvent("click", function(e){
                        var $this = this;
                        var newIndex = $this.hasClass("prev") ? index - 1 :
                                       $this.hasClass("next") ? index + 1 :
                                       $this.hasClass("heroSlideLink") ?  $slideLinks.indexOf(this) : -1;

                        showSlide( newIndex );
                        e.preventDefault();
				    });

                });

                 var timeout;
				function showSlide(newIndex)
                {
                    //debugger;
					newIndex = (newIndex < 0) ? $slides.length - 1 : (newIndex >= $slides.length) ? 0 : newIndex;

					if (newIndex != index)
                    {
						index = newIndex;

						//$slides.stop(true, true); // stop currently running animations

						//$slides.filter(".current").fadeOut(function(){
						//	$(this).removeClass("current").hide();
						//});
                        var curItem = $slides.filter(function(item, index){ if(item.hasClass('heroCurrent')) return item;});
                        curItem.fade('out').removeClass('heroCurrent');
                        //curItem.fade('hide');
                        //curItem.fade('in').addClass('heroCurrent');
						//$slides.eq(index).fadeIn(function(){
						//	$(this).addClass("current");
						//});

                        //curItem.set({'styles': {'display': 'none'}});

                        //$slides[index].set({'styles': {'display': 'block'}});
                        //$slides[index].addClass('heroCurrent');
                        $slides[index].fade('hide');
                        $slides[index].fade('in').addClass('heroCurrent');
                        //$slides[index].fade('show');

						$slideLinks.removeClass("current");
                        $slideLinks[index].addClass('current');
					}

					// auto change slides
					clearTimeout(timeout);
					if (heroNavManager.autoChangeDelay > 0) {
						timeout = setTimeout(function(){
							showSlide(index + 1);
						}, heroNavManager.autoChangeDelay * 1000)
					}
				}


            });

        });



	}
};

heroNavManager.init();


/*
$(document).ready(function(){
			$('div.heroWrapper').each(function(){
				var $hero = $(this);
				var $slides = $hero.find("div.heroSlide");
				var $controls = $hero.find("div.heroNavigation");
				var $slideLinks = $controls.find("a.heroSlideLink");

				var index = $slides.filter(".current").index();
				showSlide(index);

				$controls.delegate("a", "click", function(e){
					var $this = $(this);
					var newIndex = $this.hasClass("prev") ? index - 1 :
								   $this.hasClass("next") ? index + 1 :
								   $this.hasClass("heroSlideLink") ? $slideLinks.index($this) : -1;

					showSlide( newIndex );
					e.preventDefault();
				});

				// shows slide with given index
				var timeout;
				function showSlide(newIndex){
					newIndex = (newIndex < 0) ? $slides.length - 1 : (newIndex >= $slides.length) ? 0 : newIndex;

					if (newIndex != index) {
						index = newIndex;

						$slides.stop(true, true); // stop currently running animations

						$slides.filter(".current").fadeOut(function(){
							$(this).removeClass("current").hide();
						});
						$slides.eq(index).fadeIn(function(){
							$(this).addClass("current");
						});

						$slideLinks.removeClass("current").eq(index).addClass("current");
					}

					// auto change slides
					clearTimeout(timeout);
					if (SKYPE.components.hero.autoChangeDelay > 0) {
						timeout = setTimeout(function(){
							showSlide(index + 1);
						}, SKYPE.components.hero.autoChangeDelay * 1000)
					}
				}

			});
		});*/
