$(document).ready(function()
{
	slide("#sliding-navigation", 25, 15, 120, .8);

//	htoFlash("h1");	
	
	$('a[rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
	
	sliderload()
    setInterval( "slideSwitch()", 10000 );	
	//initScroll(); 
	inithoverfader();
});
function inithoverfader() {
	
	
	
		$(".image_container a").animate({opacity: "0.8"}, 300);
        $(".image_container a").hover(
           function() {
              $(this).animate({opacity: "1"}, 300);
        },
        function() {
               $(this).animate({opacity: "0.8"}, 300);
             
        });
	
}
function htoFlash(elem)
{
	 $(elem).flash(
        { 
            src: 'assets/fla/itc_century.swf', 
            flashvars: { 
                css: [
                    '* { color: #666666; }',
                    'a { color: #0099CC; text-decoration: none; }',
                    'a:hover { text-decoration: underline; }'
                ].join(' ')
            }
        },
        { version: 7 },
        function(htmlOptions) {
            htmlOptions.flashvars.txt = this.innerHTML;
            this.innerHTML = '<div>'+this.innerHTML+'</div>';
            var $alt = $(this.firstChild);
            htmlOptions.height = $alt.height();
            htmlOptions.width = $alt.width();
            $alt.addClass('alt');
            $(this)
                .addClass('flash-replaced')
                .prepend($.fn.flash.transform(htmlOptions));						
        }
    );
	

}
function initScroll() {
	
	 function filterPath(string) {
  return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
  }
  var locationPath = filterPath(location.pathname);
  var scrollElem = scrollableElement('html', 'body');

  $('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
    if (  locationPath == thisPath
    && (location.hostname == this.hostname || !this.hostname)
    && this.hash.replace(/#/,'') ) {
      var $target = $(this.hash), target = this.hash;
      if (target) {
        var targetOffset = $target.offset().top;
        $(this).click(function(event) {
          event.preventDefault();
          $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
            location.hash = target;
          });
        });
      }
    }
  });

  // use the first element that is "scrollable"
  function scrollableElement(els) {
    for (var i = 0, argLength = arguments.length; i <argLength; i++) {
      var el = arguments[i],
          $scrollElement = $(el);
      if ($scrollElement.scrollTop()> 0) {
        return el;
      } else {
        $scrollElement.scrollTop(1);
        var isScrollable = $scrollElement.scrollTop()> 0;
        $scrollElement.scrollTop(0);
        if (isScrollable) {
          return el;
        }
      }
    }
    return [];
  }

}
	
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    var $sibs  = $active.siblings();
    var rndNum = Math.floor(Math.random() * $sibs.length );
    var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function sliderload()
{
		// slider
	// doch: http://jqueryfordesigners.com/coda-slider-effect/
	if ($('#slider').length==0) return;
	var $panels = $('#slider .scrollContainer > div');
	var $container = $('#slider .scrollContainer');
	var horizontal = true;
	if (horizontal) {
	  $panels.css({
	    'float' : 'left',
	    'position' : 'relative' // IE fix to ensure overflow is hidden
	  });
	  $container.css('width', $panels[0].offsetWidth * $panels.length);
	}
	var $scroll = $('#slider .scroll').css('overflow', 'hidden');
	$scroll
	  .before('<img class="scrollButtons left" src="images/scroll_left.png" />')
	  .after('<img class="scrollButtons right" src="images/scroll_right.png" />');
	function selectNav() {
	  $(this)
	    .parents('ul:first')
	      .find('a')
	        .removeClass('selected')
	      .end()
	    .end()
	    .addClass('selected');
	}
	
	$('#slider .slidernav').find('a').click(selectNav);
	function trigger(data) {
	  var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
	  selectNav.call(el);
	}
	
	if (window.location.hash) {
	  trigger({ id : window.location.hash.substr(1) });
	} else {
	  $('ul.slidernav a:first').click();
	}
	var offset = parseInt((horizontal ? 
	  $container.css('paddingTop') : 
	  $container.css('paddingLeft')) 
	  || 0) * -1;
	
	
	var scrollOptions = {
	  target: $scroll, 
	  items: $panels,
	  
	  navigation: '.slidernav a',	  
	  prev: 'img.left', 
	  next: 'img.right',
	  axis: 'xy',
	  onAfter: trigger, // our final callback
	  offset: offset,
	  duration: 500,
	  // http://gsgd.co.uk/sandbox/jquery/easing/
	  easing: 'swing'
	};
	$('#slider').serialScroll(scrollOptions);
	$.localScroll(scrollOptions);
	scrollOptions.duration = 1;
	$.localScroll.hash(scrollOptions);
}
function slide(navigation_id, pad_out, pad_in, time, multiplier)
{
	// creates the target paths
	var list_elements = navigation_id + " li.sliding-element";
	var link_elements = list_elements + " a";
	
	// initiates the timer used for the sliding animation
	var timer = 0;
	
	// creates the slide animation for all list elements 
/*	$(list_elements).each(function(i)
	{
		// margin left = - ([width of element] + [total vertical padding of element])
		$(this).css("margin-left","-180px");
		// updates timer
		timer = (timer*multiplier + time);
		$(this).animate({ marginLeft: "0" }, timer);
		$(this).animate({ marginLeft: "15px" }, timer);
		$(this).animate({ marginLeft: "0" }, timer);
	});
*/
	// creates the hover-slide effect for all link elements 		
	$(link_elements).each(function(i)
	{
		$(this).hover(
		function()
		{
			$(this).animate({ paddingLeft: pad_out }, 150);
		},		
		function()
		{
			$(this).animate({ paddingLeft: pad_in }, 150);
		});
	});
}



