var page_height = 200;
function trim(value) {
	return value.replace(/^\s*/, "").replace(/\s*$/, "");
}


function is_numeric(value) {
   return (value - 0) == value && value.length > 0;
}

function email_check(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (reg.test(email)) return true;
	else return false;
}

function login_check(login) {
	var reg = /^[A-Za-z0-9_]{3,20}$/;
	if (reg.test(login)) return true;
	else return false;
}

function trim2(string)
{
	return string.replace(/(^\s+)|(\s+$)/g, "");
}

$(document).ready(function() {
            $("a.fancybox ,.fancybox").fancybox(
            
        {
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over"> (' +  (currentIndex + 1) + ' / ' + currentArray.length + ')   ' + title + '</span>';
		}
	}
                );
   
   $("a.newsbox").fancybox(
            
        {
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
		
	}
                );
  
  
  /*
   *FAQ
   */
  
    $(".faq_title").click(function(){
        $(".faq_content").slideUp(200);
        $("#"+$(this).attr('id')+"_content").slideDown();

    });
        
        


  
  /*
   *Tab Navigation
   **/
  $(".buttonwrapper a").click(function(){

    var tab_num = $(this).attr("tab");
    $(".buttonwrapper a span").removeClass();
    $(".TopContent .tab_content").stop(true,true).hide().animate({"opacity":"0%"},"slow");

    $(".TopContent #tab_page_"+tab_num).stop(true,true).show().animate({"opacity":"100%"},"slow"); 
    $(this).find("span").addClass("active");
  });
  
  
   page_height = (Math.round((parseInt($(".TopContent").height())-100)/17)+1)*17;
  
  
  $(".tab_content").height(page_height+100);
  
  $(".page_split").height(page_height);
  
  $(".page_split").each(function(index){
   var ID = ($(this).attr('tab'));   
   var page_pos = $("#tab_"+ID+" .wide").position();
   page_pos = page_pos.top;
   var page_c = $("#tab_"+ID+" .wide").height() / page_height;
   if(page_c >1){
     for(I=0;I<=page_c;I++){
        $("#nav_pages_"+ID).append("<a class='page_nums go_page' tab='"+ID+"'  page='"+(I+1)+"'>"+(I+1)+"</a>"); 
    }
   }else{
     $("#nav_"+ID).hide(); 
   }
  });

  $(".go_page").live({
     click:function(){
       if(go_page($(this).attr("tab"),$(this).attr("page"))){
         $("#nav_pages_"+$(this).attr("tab")+" a").removeClass("active");
        if(parseInt($(this).attr("page")) > 0)
        $(this).addClass("active");
       };
     }
  });
     
 /*     alert( $(this).attr('tab'));
     
      page_pos = page_pos.top;
      page_pos = page_pos- page_height;

 

 });
  
  */
  
  

});

function split_pages(Tab){
  
  //alert(Tab);
}

function go_page(ID,page){
    var page_pos = $("#tab_"+ID+" .wide").position();
      
     
       
     if(page == "next"){
        new_page_top = page_pos.top - page_height;
     } 
     if(page == "prev"){
        new_page_top = page_pos.top + page_height;
     }
     if(parseInt(page) > 0){
       new_page_top =  (parseInt(page)-1)*(-page_height);
     }
     if(page_pos.top ==new_page_top ) return false;
    $("#tab_"+ID+" .wide").animate({"opacity":0}, "fast"); 
    $("#tab_"+ID+" .wide").animate({"top":new_page_top}, "fast"); 
    $("#tab_"+ID+" .wide").animate({"opacity":100}, "fast"); 
    return true;
}
