
	
var defaults = {
			currentOffset: 0,
			maxOffset : 0,
			introTime : 6000, // was 3000
			autoIntro : true,
			slideSpeed: 1000
      };
      
var options = $.extend(defaults, options);
var tmpcont = null;

function slideIntro() {
  if (options.autoIntro) {
    if ($('#intro .screen').scrollLeft() < options.maxOffset) {
      options.currentOffset += 1000;
    } else {
      options.currentOffset = 0;
    }
    $('#intro .screen').stop().animate({'scrollLeft': options.currentOffset}, options.slideSpeed); // was 500

    introTimeout = setTimeout(slideIntro, options.introTime);
  }
}


function correctAnchors() {
	
	  $('a[href*=#]').click(function() {

    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {

            var $target = $(this.hash);

            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			//console.log("target: ",$target.attr("class"));
            if ($target.length && $target.attr("class")=='item-right') {

                var targetOffset = $target.offset().top - 30;

                $('html,body').animate({scrollTop: targetOffset}, 400);

                return false;

            }

        }

    	});
	
	
}

function initIntro() {
  if ($('#intro').length == 0) return false;
  
  $('#intro .panel').each(function(idx) {
    $(this).css('left', 1000*idx);
    options.maxOffset = 1000*idx;
  });
  
  $('#intro .tabs li a').hover(
    function() {
      options.autoIntro = false;
      clearTimeout(introTimeout);
      var pnl = $(this).attr('rel');
      options.currentOffset = parseInt($('#intro '+pnl).css('left').replace('px', ''));
      $('#intro .screen').scrollLeft(options.currentOffset);
    },
    function() {
      options.autoIntro = true;
      introTimeout = setTimeout(slideIntro, options.introTime*3);
    }
  );

  introTimeout = setTimeout(slideIntro, options.introTime);
}


var newsTime = 2000;

function slideNews() {
  var currentNews = $('#news-bar li:first-child');
  currentNews.stop().animate({'opacity':'0', 'margin-top': '-26px'}, 1000, function() {
    $('#news-bar').append('<li>'+currentNews.html()+'</li>');
    currentNews.remove();
    newsTimeout = setTimeout(slideNews, newsTime);
  });
}

function initNews() {
  if ($('#news-bar').length == 0 || $('#news-bar li').length < 2) return false;
  newsTimeout = setTimeout(slideNews, newsTime);
}

function initMenu() {
  $('.menu').mouseover(function() {
      //$('#menu').show();
      $('#menu').fadeIn("fast");
    return false;
  });
  
  $('#menu').bind("mouseleave",function(){
	$('#menu').fadeOut("fast");
  	return false; 
  });
}

// functions for control video 

function videoTemp() {
				initVideoLinks();
              
}


function close_vid() {
		
                tmpcont.fadeOut("slow",function() {
                $('#intro').fadeIn("slow");
                $('.subheader').fadeIn('slow');
                $('#tabs').fadeIn('slow');
  														   });
				return false;
}


function initVideoLinks() {
    if ( $.browser.msie && $.browser.version<8) {
 		initVideoLinksIe();
    }else {
    	initVideoLinksIe();	
    }
	
}

 

$(document).ready(function() {
  initIntro();
  initNews();
  initMenu();
  correctAnchors();
});
 


function initVideoLinksIe() {
  $( "a.video" ).each(
	 function( intIndex, elem ){
		 //console.log("element href: ",elem.href);
		 $( this ).bind (
			 "click",
				 function(ev){
			 	ev.preventDefault();
			 		// if video is run from popub content close this popup
				 	if ($('#lbOverlay')) {
				 		$('#lbCenter').hide();
						$('#lbOverlay').stop().hide();
				 	}

			 	
					var tmpclass = elem.id+"_frame";
                	tmpcont = $('<div id="subheader_movie" />').hide().prependTo($('#content'))
	                $('<a href="#" id="lbCloseLink_movie"></a>').prependTo($('#subheader_movie')).click(close_vid)[0];
		              
      	              $('<iframe />', {
    	            	'class': tmpclass,
        	            width: "800",
            	        height: "450",
                	    frameborder:"0",
                    	style: "border:1px solid #cccccc; width:800px; height:450px; vertical-align:middle; ",
	                    src: elem.href,
    	                id: "movie_frame"
        	           }).appendTo($('#subheader_movie'));
               	      
               	
                $('#intro').fadeOut("slow",function() {
							tmpcont.fadeIn("slow");
  													});
                
                $('.subheader').fadeOut('slow',function() {
							tmpcont.fadeIn("slow");
  														   }
  										);
                $('#tabs').fadeOut('slow');
				  }
		   );
 		}

	);
}



function initVideoLinks_new() {
  $( "a.video" ).each(
	 function( intIndex, elem ){
		 $( this ).bind (
			 "click",
				 function(ev){
			 	ev.preventDefault();
					var tmpclass = elem.id+"_div";
					var tmpcont = null;
					if ($('.'+elem.id+"_div").length){
				  			tmpcont = $('.'+elem.id+"_div")[0]; 
				  			tmpcont =  $(tmpcont);
				  	} else{
	                		tmpcont = $('<div id="subheader_movie"/>');
    	            		tmpcont.addClass(tmpclass); 
	        	        	tmpcont.css({ 'opacity' : 0 });
    	    	        	tmpcont.prependTo($('#content'));
	    	    	        $('<a href="#" id="lbCloseLink_movie"></a>').prependTo($('#subheader_movie')).click(
	                						  function() {
	                						   tmpcont.animate({opacity:0, height:0},"slow",function() {
								                $('#intro').fadeIn("slow");
									           $('.subheader').fadeIn('slow');
								                $('#tabs').fadeIn('slow');
																				 });
	                						  }
	           				)[0];
 					  var tmpclass = elem.id+"_frame";
      	              $('<iframe />', {
      	              	'class': tmpclass,
        	            width: "800",
            	        height: "450",
                	    frameborder:"0",
                    	style: "border:1px solid #cccccc; width:800px; height:450px; vertical-align:middle; ",
	                    src: elem.href,
    	                id: "movie_frame"
        	           }).appendTo($('#subheader_movie'));
               	  } // end else new element 
               	  
                $('#intro').fadeOut("slow",function() {
							tmpcont.animate({opacity:1, height:'450px'},"slow");
							
				});
                
                $('.subheader').fadeOut('slow',function() {
							tmpcont.animate({opacity:1},"slow");
			                $('#tabs').fadeOut('slow');
				 });
 		});
 		});
}


