// head box changer

var head_box_timer;
var head_box_subtimer;
var head_box_active = 1;
var head_box_interval = 5000;

$(document).ready(function(){
   
   head_box_timer = setInterval(function(){ head_box_show_next(); }, head_box_interval);
   
   $("#head_box_prev").click(function(){
      head_box_show_prev();
      return false;
   });
   
   $("#head_box_next").click(function(){
      head_box_show_next();
      return false;
   });
   
});

function head_box_show(id){
   
   clearInterval(head_box_timer);
   clearInterval(head_box_subtimer);
   
   if((!$("#head_box_"+head_box_active).is(":animated")) && (!$("#head_box_"+id).is(":animated"))){
   
      $("#head_box_"+head_box_active).fadeOut();
      head_box_subtimer = setTimeout(function(){ $("#head_box_"+id).fadeIn(); }, 400);
      
      head_box_active = parseInt(id);
      
      head_box_timer = setInterval(function(){ head_box_show_next(); }, head_box_interval);
      
   }
   
}

function head_box_show_prev(){
   
   prev = head_box_active - 1;
   
   if(prev == 0) prev = $("#image_box .subbox").size();
   
   head_box_show(prev);
   
}

function head_box_show_next(){
   
   next = head_box_active + 1;
   
   if(next > $("#image_box .subbox").size()) next = 1;
   
   head_box_show(next);
   
}

// news box changes

var news_box_timer;
var news_box_active = 1;
var news_box_interval = 8000;

$(document).ready(function(){
   
   $("#news_box_prev").click(function(){
      news_box_show_prev();
      return false;
   });
   
   $("#news_box_next").click(function(){
      news_box_show_next();
      return false;
   });
   
});

function news_box_show(id){
   
   clearInterval(news_box_timer);
   
   if((!$("#news_box_"+news_box_active).is(":animated")) && (!$("#news_box_"+id).is(":animated"))){
      
      $("#news_box_"+news_box_active).fadeOut();
      news_box_timer = setTimeout(function(){ $("#news_box_"+id).fadeIn(); }, 400);
      
      news_box_active = parseInt(id);
      
   }
   
}

function news_box_show_prev(){
   
   prev = news_box_active - 1;
   
   if(prev == 0) prev = $("#news_box .news_subbox").size();
   
   news_box_show(prev);
   
}

function news_box_show_next(){
   
   next = news_box_active + 1;
   
   if(next > $("#news_box .news_subbox").size()) next = 1;
   
   news_box_show(next);
   
}

// pr box changes

var pr_box_timer;
var pr_box_active = 1;
var pr_box_interval = 8000;

$(document).ready(function(){
   
   $("#pr_box_prev").click(function(){
      pr_box_show_prev();
      return false;
   });
   
   $("#pr_box_next").click(function(){
      pr_box_show_next();
      return false;
   });
   
});

function pr_box_show(id){
   
   clearInterval(pr_box_timer);
   
   if((!$("#pr_box_"+pr_box_active).is(":animated")) && (!$("#pr_box_"+id).is(":animated"))){
   
      $("#pr_box_"+pr_box_active).fadeOut();
      pr_box_timer = setTimeout(function(){ $("#pr_box_"+id).fadeIn(); }, 400);
      
      pr_box_active = parseInt(id);
      
   }
   
}

function pr_box_show_prev(){
   
   prev = pr_box_active - 1;
   
   if(prev == 0) prev = $("#pr_box .pr_subbox").size();
   
   pr_box_show(prev);
   
}

function pr_box_show_next(){
   
   next = pr_box_active + 1;
   
   if(next > $("#pr_box .pr_subbox").size()) next = 1;
   
   pr_box_show(next);
   
}

// dropdown

var dropdown_visible = 0;

$(document).ready(function(){
   
   $("#dropdown_container").hide(0);
   
   $("#dropdown_container").find(".close").click(function(){
      $("#dropdown_container").hide(0);
      return false;
   });
   
});

function dropdown_toggle(){
   
   if(dropdown_visible){
      dropdown_hide();
   }
   else{
      dropdown_show();
   }
   
}

function dropdown_show(){
   
   $("#dropdown_container").fadeIn(200);
   
   dropdown_visible = 1;
   
}

function dropdown_hide(){
   
   $("#dropdown_container").fadeOut(200);
   
   dropdown_visible = 0;
   
}

// select

$(document).ready(function(){
   
   $("#select_container").hide(0);
   
   $("#select_container").prev("a").click(function(){
      $("#dropdown_container").hide(0);
      $("#select_container").toggle(0);
      return false;
   });
   
   $("#select_container").find("a").click(function(){
      var select_content = $(this).text();
      var select_href = $(this).attr('href');
      var select_id = select_href.substr(1);
      $("#select_container").prev("a").text(select_content).attr('href', select_href);
      $("#select_container").hide(0);
      $("#dropdown_container").find(".dropdown_content").css('display', 'none');
      $("#dropdown_content_"+select_id).show(0);
      $("#dropdown_container").show(0);
      return false;
   });
   
});
