/* Copyright (C) YOOtheme GmbH, YOOtheme Proprietary Use License (http://www.yootheme.com/license) */

(function($){

	$(document).bind('ready', function() {

		/* Accordion menu */
		$('.menu-accordion').accordionMenu({ mode:'slide' });

		/* Dropdown menu */
		$('#menu').dropdownMenu({ mode: 'diagonal', dropdownSelector: 'div.dropdown', fancy: { mode: 'move', transition: 'easeOutExpo', duration: 500 } }).dropdownMenu("matchUlHeight");

		/* set hover color */
		switch (Warp.Settings.color) {
			case 'ocean':
				var menuEnter = '#cbdbe1';
				var menuLeave = '#DEEAEF';
				var submenuEnter = '#273c48';
				var submenuLeave = '#2e4552';
				break;	
			case 'red':
				var menuEnter = '#e6e3e1';
				var menuLeave = '#EFEEED';
				var submenuEnter = '#292222';
				var submenuLeave = '#312828';
				break;	
			case 'green':
				var menuEnter = '#dadcc1';
				var menuLeave = '#E6E8D0';
				var submenuEnter = '#2f2f27';
				var submenuLeave = '#36362e';
				break;	
			case 'brown':
				var menuEnter = '#d0cdbc';
				var menuLeave = '#DBD9CC';
				var submenuEnter = '#45403b';
				var submenuLeave = '#4e4943';
				break;	
			case 'ecru':
				var menuEnter = '#cdccb7';
				var menuLeave = '#D8D7C7';
				var submenuEnter = '#2a2a22';
				var submenuLeave = '#313128';
				break;	
			case 'blue':
				var menuEnter = '#d9e8f7';
				var menuLeave = '#EBF3FF';
				var submenuEnter = '#154d85';
				var submenuLeave = '#1b558f';
				break;	
			case 'white':
				var menuEnter = '#c9d1d9';
				var menuLeave = '#D7DEE6';
				var submenuEnter = '#576069';
				var submenuLeave = '#646e78';
				break;	
			default:
				var menuEnter = '#C8D0D7';
				var menuLeave = '#D8DEE2';
				var submenuEnter = '#262A2D';
				var submenuLeave = '#2B2F32';
		}


		/* Morph: main menu - level2 (bg) */
		var menuEnter = { 'background-color': menuEnter };
		var menuLeave = { 'background-color': menuLeave };

		$('#menu a.level2').morph(menuEnter, menuLeave,
			{ transition: 'swing', duration: 0, ignore: '#menu li.level2 a.parent' },
			{ transition: 'easeInSine', duration: 500 });

		/* Morph: mod-fading sub menu - level1 (bg) */
		var submenuEnter = { 'background-color': submenuEnter };
		var submenuLeave = { 'background-color': submenuLeave };

		$('div.mod-sidebar ul.menu li.level2 a, div.mod-sidebar ul.menu li.levek2 span.separator').morph(submenuEnter, submenuLeave,
			{ transition: 'swing', duration: 0 },
			{ transition: 'easeInSine', duration: 300 });

		/* Smoothscroll */
		$('a[href="#page"]').smoothScroller({ duration: 500 });

		/* Match height of div tags */
		$('div.headerbox div.deepest').matchHeight(20);
		$('div.topbox div.deepest').matchHeight(20);
		$('div.bottombox div.deepest').matchHeight(20);
		$('div.maintopbox div.deepest').matchHeight(20);
		$('div.mainbottombox div.deepest').matchHeight(20);
		$('div.contenttopbox div.deepest').matchHeight(20);
		$('div.contentbottombox div.deepest').matchHeight(20);

	});

})(jQuery);

var YJSlide = new Class({
  initialize: function (A) {
    this.options = Object.extend({
      outerContainer: null,
      innerContainer: null,
      elements: null,
      navigation: {
        forward: null,
        back: null
      },
      slideType: 0,
      orientation: 1,
      slideTime: 1000,
      duration: 600,
      tooltips: 1,
      autoslide: 1,
      navInfo: null,
      navLinks: null
    }, A || {});
    this.start()
  },
  start: function () {
    this.currentElement = 0;
    this.direction = 1;
    this.elements = $(this.options.innerContainer).getElements(this.options.elements);
    this.showEffect = {};
    this.hideEffect = {};
    if (this.options.slideType !== 0) {
      if (this.options.orientation == 1) {
        this.showEffect.left = [1200, 0];
        this.hideEffect.left = [0, 1200]
      } else {
        this.showEffect.top = [400, 0];
        this.hideEffect.top = [0, 400]
      }
    }
    if (this.options.slideType !== 1) {
      this.showEffect.opacity = [0, 1];
      this.hideEffect.opacity = [1, 0]
    }
    this.elements.each(function (B, A) {
      B.setStyles({
        display: "block",
        position: "absolute",
        top: 0,
        left: 0,
        "z-index": (100 - A)
      });
      if (this.options.slideType !== 1 && A !== this.currentElement) {
        B.setStyle("opacity", 0)
      }
      this.elements[A]["fx"] = new Fx.Styles(B, {
        wait: false,
        duration: this.options.duration
      });
      if (A !== this.currentElement) {
        this.elements[A]["fx"].start(this.hideEffect)
      }
      B.addEvent("mouseover", function (C) {
        if ($defined(this.period)) {
          $clear(this.period)
        }
      }.bind(this));
      B.addEvent("mouseout", function (C) {
        if (this.options.autoslide == 0) {
          this.period = this.rotateSlides.periodical(this.options.slideTime, this)
        }
      }.bind(this))
    }.bind(this));
    if (!this.options.tooltips) {
      new Tips($(this.options.innerContainer).getElements(".YJS_link"), {
        className: "YJS_tips"
      })
    }
    if (!this.options.autoslide) {
      this.period = this.rotateSlides.periodical(this.options.slideTime, this)
    }
    this.setNavigation();
    if (this.options.navLinks) {
      this.secondNavigation()
    }
  },
  rotateSlides: function () {
    var A = this.currentElement + this.direction;
    if (A < 0) {
      A = this.elements.length - 1
    }
    if (A > this.elements.length - 1) {
      A = 0
    }
    this.nextSlide(A)
  },
  nextSlide: function (A) {
    if (A == this.currentElement) {
      return
    }
    this.elements[this.currentElement]["fx"].start(this.hideEffect);
    this.elements[A]["fx"].start(this.showEffect);
    this.currentElement = A;
    if ($(this.options.navInfo)) {
      $(this.options.navInfo).setHTML("Link " + (A + 1) + " of " + this.elements.length)
    }
  },
  setNavigation: function () {
    if (!$(this.options.navigation.forward)) {
      return
    }
    $(this.options.navigation.forward).addEvent("click", function (A) {
      new Event(A).stop();
      this.direction = 1;
      this.resetAutoslide();
      this.rotateSlides()
    }.bind(this));
    $(this.options.navigation.back).addEvent("click", function (A) {
      new Event(A).stop();
      this.direction = -1;
      this.resetAutoslide();
      this.rotateSlides()
    }.bind(this))
  },
  resetAutoslide: function () {
    if ($defined(this.period)) {
      $clear(this.period);
      this.period = this.rotateSlides.periodical(this.options.slideTime, this)
    }
  },
  secondNavigation: function () {
    this.navElements = $$(this.options.navLinks);
    this.navElements.each(function (B, A) {
      B.addEvent("click", function (C) {
        new Event(C).stop();
        this.resetAutoslide();
        this.nextSlide(A)
      }.bind(this))
    }.bind(this));
    if (!this.options.tooltips) {
      new Tips(this.navElements, {
        className: "YJS_tips"
      })
    }
  }
});

window.addEvent('load', function(){
			new YJSlide({
				outerContainer : 'YJSlide_outer',
				innerContainer : 'YJSlide_inner',
				elements: '.YJSlide_slide',
				navigation: {
					'forward':'null', 
					'back':'null'
				},
				slideType: 0,
				orientation: 0,
				slideTime: 4000,
				duration: 600,
				tooltips: 0,
				autoslide: 0,
				navInfo: 'YJS_nav_info',
				navLinks: '.YJS_navLink' 
			});
		});
