// JavaScript Document

/*** 
    position slider in center of page
***/
	function centerSlider(slider){
		$("#home #slider").css("left",(($("#content").width())-($("#home #slider").width()))/2);
		$("#next #slider").css("left",(($("#sliderWrapper").width())-($("#next #slider").width()))/2);
		//alert($("#home #slider").width());
	}
	
	
/*adapt width of blog posts*/
	function adaptoblog(){
		if($(document).width()>979){
			$(".one").css("margin-right",($(".two").outerWidth(true))+35);
		}else{
			$(".one").css("margin-right",0);	
		}
	}
	
	
/*** 
    equalize columns
***/
	function equalize(){
		//Equalizes height of all .col children of .threeCols.equalize 
		$(".threeCols.equalize").each(function(){
			var maxH=0;
			$(this).find(".colcontent").each(function(){
				if(($(this).height())>maxH){
					maxH=$(this).height();
				}
			});
			$(this).find(".col").each(function(){
				$(this).height(maxH);
			});
		});
		
		var maxHI=0;
		$(".services .threeCols .artImgContainer img").each(function(){
			if(($(this).height())>maxHI){
				maxHI=$(this).height();
			}
		});
		$(".services .threeCols .artImgContainer img").each(function(){
			$(this).parent().parent().css("padding-top",maxHI-($(this).height()));
		});	
	}

/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/
function slideSwitch() {
    var $active = $('#rotator li.active');

    if ( $active.length == 0 ) $active = $('#rotator li:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#rotator li:first');

    // uncomment below to pull the divs randomly
    // 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')
		.stop()
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active').stop().animate({opacity: 0.0}, 1000);
        });
}

jQuery.fn.topLink = function(settings) {
  settings = jQuery.extend({
    min: 1,
    fadeSpeed: 200
  }, settings);
  return this.each(function() {
    //listen for scroll
    var el = $(this);
    el.hide(); //in case the user forgot
    $(window).scroll(function() {
      if($(window).scrollTop() >= settings.min)
      {
        el.fadeIn(settings.fadeSpeed);
      }
      else
      {
        el.fadeOut(settings.fadeSpeed);
      }
    });
  });
};

/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/
function doubleSlider() {
	var $marginLefty = $('#doubleSlider .left');
    $('li', $marginLefty).css({
      marginLeft: $('li', $marginLefty).outerWidth() + 'px',
      display: 'block'
    });
	var $marginRighty = $('#doubleSlider .right');
    $('li', $marginRighty).css({
      left: -$('li', $marginRighty).outerWidth() + 'px',
      display: 'block'
    });
	var leftylis = $("#doubleSlider .left li").length;
/*    
		$('#doubleSlider .left').each(function() {  
			var obj = $(this); 				
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			var ts = s-1;
			var t = 0;
			t = (ot>=ts) ? (options.continuous ? t+1 : ts ) : t+1;
		});
*/
	var speed = 10000;
	var t = 0;
	var ot = 0;
	var ts = leftylis-1;
	var leftytimeout;
	function animateDouble(){
		if(t>ts) {t=0; ot=ts;}
		if(ot<=ts) {
			if (parseInt($('#doubleSlider .left li').eq(ot).css('marginLeft'),10) == 0) {
			  $('#doubleSlider .left li').eq(ot).animate({ marginLeft:$('#doubleSlider .left li').eq(ot).outerWidth()},800);
			}
			if (parseInt($('#doubleSlider .right li').eq(ot).css('left'),10) == 0) {
			  $('#doubleSlider .right li').eq(ot).animate({ left:-$('#doubleSlider .right li').eq(ot).outerWidth()},800);
			}
		}
		nexttimeout = setTimeout(function(){
		  $('#doubleSlider .left li').eq(t).animate({
			marginLeft: parseInt($('#doubleSlider .left li').eq(t).css('marginLeft'),10) == 0 ?
			$('#doubleSlider .left li').eq(t).outerWidth() : 0
		  });
		  $('#doubleSlider .right li').eq(t).animate({
			left: parseInt($('#doubleSlider .left li').eq(t).css('left'),10) == 0 ?
			0 : -$('#doubleSlider .right li').eq(t).outerWidth()
		  });
			ot = t;	
			t = t+1;
			leftytimeout = setTimeout(function(){
				animateDouble()
			},speed);
		},600);
	}
	leftytimeout = setTimeout(function(){
		animateDouble()
	},0);
	
	
	
	
};

