jQuery.event.add(window, "load", resizeFrame1);
jQuery.event.add(window, "resize", resizeFrame2);

function resizeFrame1() {
  var h=$(window).height();
  $('#content').jScrollPane({topCapHeight: 10, bottomCapHeight:10, scrollbarWidth: 5});
  $('#frame1').css('height',h-175);  
  $('.jScrollPaneContainer').css('height',h-175);
  $('#content').jScrollPane({topCapHeight: 10, bottomCapHeight:10, scrollbarWidth: 5});
};
                                            
function resizeFrame2() {
  var h=$(window).height();
  $('.jScrollPaneContainer').css('height',h-175);
  $('#frame1').css('height',h-175);
  $('#content').jScrollPane({topCapHeight: 10, bottomCapHeight:10, scrollbarWidth: 5});  
};


$(document).ready(function() {

	//Speed of the slideshow
	var speed = 5000;
	
	//You have to specify width and height in #slider CSS properties
	//After that, the following script will set the width and height accordingly
	$('#mask-gallery, #gallery li').width($('#slider').width());	
	$('#gallery').width($('#slider').width() * $('#gallery li').length);
	$('#mask-gallery, #gallery li, #mask-excerpt, #excerpt li').height($('#slider').height());
	
	//Assign a timer, so it will run periodically
	var run = setInterval('newsscoller(0)', speed);	
	
	$('#gallery li:first, #excerpt li:first').addClass('selected');
	
	//Mouse over, pause it, on mouse out, resume the slider show
	$('#slider').hover(
	
		function() {
			clearInterval(run);
		}, 
		function() {
			run = setInterval('newsscoller(0)', speed);	
		}
	);
	
	//video featured
  $("#featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 7250, true);   
	$("#featured").hover(   
    function() {   
      $("#featured").tabs("rotate",0);   
    }  
  );   

	
	//login filling
	$("input[name=login_username]").focus(function(){
  	if($(this).val()=="em@il"){
  		$(this).val("@");
  	}
  });
  
  $("input[name=login_username]").blur(function(){
  	if($(this).val()=="@"){
  		$(this).val("em@il");
  	}
  });
  
	$("input[name=login_userpass]").focus(function(){
  	if($(this).val()=="password"){
  		$(this).val("");
  		this.type='password';
  	}
  });
  
  $("input[name=login_userpass]").blur(function(){
  	if($(this).val()==""){
  		this.type='text';
      $(this).val("password");
  	}
  });

	$("input[name=subscribe_email]").focus(function(){
  	if($(this).val()=="em@il"){
  		$(this).val("@");
  	}
  });
  
  $("input[name=subscribe_email]").blur(function(){
  	if($(this).val()=="@"){
  		$(this).val("em@il");
  	}
  });
  

  //lavamenu
        $(function() {
            $("#menu_main").lavaLamp({
                fx: "backout",
                speed: 700,
                click: function(event, menuItem) {
                    return true;
                }
            });
        });
        
        
  
  //nyromodal     
  $.nyroModalSettings({
    processHandler: function(settings) {
      var from = settings.from;
      if (from && from.href && from.href.indexOf('http://www.youtube.com/watch?v=') == 0) {
        $.nyroModalSettings({
          type: 'swf',
          height: 355,
          width: 425,
          url: from.href.replace(new RegExp("watch\\?v=", "i"), 'v/')
        });
      }
    }
  ,
  minWidth:100, minHeight:100}); 
  
  Cufon.replace('#jquery-notifications, .subscribe .title, .header_contact p, #menu_main, .twitter_body, .content_news ul, .content_text_body p, .content_lineup, .footer_left p, .footer_left span, #excerpt li p', {hover:true });      
});	



function newsscoller(prev) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
	var current_excerpt = $('#excerpt li.selected').length ? $('#excerpt li.selected') : $('#excerpt li:first');

	//if prev is set to 1 (previous item)
	if (prev) {
		
		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
		var next_excerpt = (current_excerpt.prev().length) ? current_excerpt.prev() : $('#excerpt li:last');
	
	//if prev is set to 0 (next item)
	} else {
		
		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
		var next_excerpt = (current_excerpt.next().length) ? current_excerpt.next() : $('#excerpt li:first');
	}

	//clear the selected class
	$('#excerpt li, #gallery li').removeClass('selected');
	
	//reassign the selected class to current items
	next_image.addClass('selected');
	next_excerpt.addClass('selected');

	//Scroll the items
	$('#mask-gallery').scrollTo(next_image, 800);		
	$('#mask-excerpt').scrollTo(next_excerpt, 800);					
	
}

function goto(item) {
	$('#mask-gallery').scrollTo(item, 800);		
	$('#mask-excerpt').scrollTo(item, 800);	
	$(item).addClass('selected');					
}

function ShowHide(tagId) {
  if($(tagId).is(':visible')) {
    $(tagId).hide();  
  }else{
    $(tagId).fadeIn();
  }
}


