function addslashes(str) {
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\0/g,'\\0');
return str;
}
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}

function setImage(  ) {
	var path = $("#photo-one-url").val();
	var alt = $("#photo-one-text").val();
	$("#photo-one").html('<img src=' + path + ' /><p>' + stripslashes( alt ) + '</p>');
}

var rbpcurPX= 0;
var rbppos = 0;


$(document).ready(function(){


		$(".slider-body").jCarouselLite({
			btnNext: ".slider .right",
			btnPrev: ".slider .left",
			mouseWheel: true,
			visible: 4
		});

    
    var attrImg = $(".block .big-post img").attr("align");
    $(".block .big-post img").addClass(attrImg);

		
    $(".toBlog textarea").click(function() {        
      $(this).select().focus();
    }); 
    
    
		/*$('.rbp-lister-line img').click(function(){
			$('.rbp-lister-line img').animate({opacity: 1});
			$(this).animate({opacity: 0.5});
			var path = $(this).parent().attr('href');
			var alt = $(this).attr('alt');
			$('.rbp-body').animate({opacity: 0},500,function(){
				$(this).html('<img src=' + path + ' />').find('img').bind('load',function(){
					$(this).parent().append('<p>' + alt + '</p>').animate({opacity: 1},500);
				});
			});
		return false;
		});*/
		/*$('.rbp-lister-line img:first').click(); */

		

		
		$('.gallery-lister img').click(function(){
			var path = $(this).parent().attr('href');
			var text = $('p',$(this).parents('.bDarkList'));

			$('.bppContent').html('<img src=' + path + ' />').find('img').bind('load',function(){
			          $(this).parent().append(text.clone().width($(this).width()));
			});

			$('.gallery-lister img').animate({opacity: 1});
			$(this).animate({opacity: 0.5});
			$('.bigphotopopup').show('fast');

		return false;
		});
	$('.gallery-lister .zoom').click(function(){
											  
			$(this).parent().find('img').click();
			return false;				

		});		
		
		$('.bigphotopopup').click(function(){
			$('.gallery-lister img').animate({opacity: 1});
			$(this).hide('fast');		
		});




$('.gallery-lister2 img').click(function(){
			$('.gallery-lister2 img').animate({opacity: 1});
			$(this).animate({opacity: 0.5});
			$('.bigphotopopup2').show('fast');
			var path = $(this).parent().attr('href');
			var text = $('p',$(this).parents('.bDarkList'));
			$('.bppContent').animate({opacity: 0},500,function(){
				$(this).html('<img src=' + path + ' />').find('img').bind('load',function(){
          $(this).parent().append(text.clone()).animate({opacity: 1},500);
				});
			});
		return false;
		});
	$('.gallery-lister2 .zoom').click(function(){
											  
			$(this).parent().find('img').click();
			return false;				

		});		
		
		$('.bigphotopopup2').click(function(){
			$('.gallery-lister2 img').animate({opacity: 1});
			$(this).hide('fast');		
		});



		
		var rbpwidth = $(".rbp-lister-line nobr").width();
		if (rbpwidth > 590) {
			$(".rbp-lister .left-a, .rbp-lister .right-a").show();
			}

		var rbpcount = $(".rbp-lister a").length - 1;
/*		var rbpcurPX= 0;
		var rbppos = 0;*/
		$('.rbp-lister .left-a').click(function(){
			if (rbppos > 0) {
				rbppos--;									
				var rbpcurImg= $(".rbp-lister-line a").eq(rbppos).width()+3;										
				rbpcurPX = rbpcurPX - rbpcurImg; 
				$(".rbp-lister-line a").eq(rbppos).width();													
				$(".rbp-lister-line nobr").animate({ left: '-'+(rbpcurPX-14) });	

			}
			
		});
		$('.rbp-lister .right-a').click(function(){
			if (rbppos < rbpcount) {
				
				var rbpcurImg= $(".rbp-lister-line a").eq(rbppos).width()+3;
				rbpcurPX = rbpcurPX + rbpcurImg; 
				
				$(".rbp-lister-line nobr").animate({ left: '-'+(rbpcurPX-14) });
				rbppos++;				
			}
			
		});
		
		var VGheight = $(".vert-gallery .gallery-lister").height();
    	var VGvisible = $(".vert-gallery .gallery-body").height();
		var VGcount = $(".vert-gallery .bDarkList").length;
		var VGcurPX= 0;
		var VGpos = 1;
		/*$('.vert-gallery .debug').html(VGheight + ' ' + VGcount + ' ' + VGpos  );*/

		/*var VGbodyheight = ($(".vert-gallery .gallery-lister a").eq(0).height())+($(".vert-gallery .gallery-lister a").eq(1).height());
		$('.vert-gallery .gallery-body').css("height", VGbodyheight+'px' );*/


		$('.vert-gallery .arrow-down').click(function(){
			if (VGpos <= VGcount) {

				var VGcurImg= $(".vert-gallery .bDarkList").eq(0).height();
				var VGnextImg= $(".vert-gallery .bDarkList").eq(VGpos).position().top + "px";
				
				var VGnextImgHeight= $(".vert-gallery .bDarkList").eq(VGpos).height();
				var VGprevImgHeight= $(".vert-gallery .bDarkList").eq(VGpos-1).height();
				
				VGcurPX = VGheight - VGvisible;

        		if(VGcount == 1)
        		{
					$(".vert-gallery .gallery-lister").animate({ top: '-'+VGcurPX });
        		}
        		else
        		{
        			if (VGpos < VGcount)
        			{
        				
          				//$(".vert-gallery .gallery-lister").animate({ top: '-'+VGnextImg });
          				//alert(VGnextImg);
        				if (VGpos == (VGcount-1))
        				{
        					
        					if ((VGvisible - VGnextImgHeight) > 0)
        					{
        						var vhx = VGnextImg= $(".vert-gallery .bDarkList").eq(VGpos-1).position().top + Math.abs(VGvisible - ($(".vert-gallery .bDarkList").eq(VGpos-1).height() + $(".vert-gallery .bDarkList").eq(VGpos).height()));
        						$(".vert-gallery .gallery-lister").animate({ top: '-'+vhx+'px' });
        					}
        					else
        					{
        						$(".vert-gallery .gallery-lister").animate({ top: '-'+VGnextImg });
        					}
        					
        					
        				}
        				else
        				{
        					$(".vert-gallery .gallery-lister").animate({ top: '-'+VGnextImg });
        				}
          			}
        		}
				VGpos++;
				/*$('.vert-gallery .debug').html(VGheight + ' ' + VGcount + ' ' + VGpos  );*/
			}
		});
		$('.vert-gallery .arrow-up').click(function(){
			if (VGpos > 1) {
				VGpos--;
				var VGcurImg= $(".vert-gallery .bDarkList").eq(0).height();
				var VGnextImg= $(".vert-gallery .bDarkList").eq(VGpos -1).position().top + "px";
				VGcurPX = VGheight - VGvisible;
				$(".vert-gallery .bDarkList").eq(VGpos).height();
				$(".vert-gallery .gallery-lister").animate({ top: '-'+VGnextImg });
        //$(".vert-gallery .gallery-lister").animate({"top":"-" +  $top.next().position().top + "px"}

				/*$('.vert-gallery .debug').html(VGheight + ' ' + VGcount + ' ' + VGpos  );*/
			}

		});

		$('.videoresize .video-preview').click(function(){
			$(this).parent().find('.resizeble-player').show("slow");
		});
		$('.videoresize .resizeble-player .close-player').click(function(){
			$(this).parent().hide("slow");
		});
	

		$(".right-col .bCareers tr:even, .readest div div:even, .Commentest div div:even, .center-col .bCareers tr:odd ").addClass('odd');		
		
		$(".openReadest").click(function() {
			//$(".links a").removeClass("current");			
			$(this).addClass("current");
			$(this).next().removeClass("current");
			//$(".readest, .readest .all").show();
			$(".Commentest").css("display","none");
			$(".readest").css("display","block");
      		//$(".readest .all, .readest .week").hide();
		});
		
		$(".openCommentest").click(function() {
			//$(".links a").removeClass("current");
			//$(this).addClass("current");
			$(this).addClass("current");
			$(this).prev().removeClass("current");											
			$(".Commentest").css("display","block");
			$(".readest").css("display","none");
			//$(".Commentest .Comment_week").hide();
			//$(".Commentest .all").show();			
		});
		
		/*$(".togglePeriod").click(function() {
			$(".bPopular .rLink a").removeClass("current");			
			$(this).addClass("current");
			var popShow = '.'+$(this).attr("rel");
			$(this).parent().parent().find(".week, .all, .Comment_day, .Comment_week").hide();
			$(popShow).show();
		});*/
		
		$(".Commentest .rLink a").click(
			function() {
				if ($(this).attr('rel') == 'Comment_day')
				{
					$(this).addClass("current");
					$(this).next().removeClass("current");
					$(this).parent().siblings('.Comment_day').css('display','block');
					$(this).parent().siblings('.Comment_week').css('display','none');
          return false;
				}
				if ($(this).attr('rel') == 'Comment_week')
				{
					$(this).addClass("current");
					$(this).prev().removeClass("current");
					$(this).parent().siblings('.Comment_day').css('display','none');
					$(this).parent().siblings('.Comment_week').css('display','block');
          return false;
				}
			}
		);
		
		$(".readest .rLink a").click(
			function() {
				if ($(this).attr('rel') == 'day')
				{
					$(this).addClass("current");
					$(this).next().removeClass("current");
					$(this).parent().siblings('div.day').css('display','block');
					$(this).parent().siblings('div.week').css('display','none');
          return false;
				}
				if ($(this).attr('rel') == 'week')
				{
					$(this).addClass("current");
					$(this).prev().removeClass("current");
					$(this).parent().siblings('div.day').css('display','none');
					$(this).parent().siblings('div.week').css('display','block');
          return false;
				}
			}
		);

		$(".block-main .photos .changer a").click(function() {		

		});
		$(".toBlogLink").click(function() {		
			var intoBlogLeftP = Math.floor($(this).parent().offset().left);
			var intoBlogTopP = Math.floor($(this).parent().offset().top);										
			var intoBlogLeft =  Math.floor($(this).offset().left)+25 - intoBlogLeftP +'px';
			var intoBlogTop = Math.floor($(this).offset().top)+5- intoBlogTopP + 'px';
			var intoBlogId = "#toBlog"+$(this).attr("rel");
			/*alert (intoBlogLeft +' '+intoBlogTop+' '+intoBlogId);*/
			
			$(intoBlogId).show().css('left',intoBlogLeft).css('top',intoBlogTop);
		});
		$(".toBlogClose").click(function() {		
			$(this).parent().hide();
		});	
		var sizeF = 100;
		$("#plusF").click(function() {
			sizeF = sizeF+10;
			$(".block .anons").css("font-size",sizeF+"%");
			$(".block .big-post").css("font-size", sizeF+"%");
			$(".block .big-post").css("line-height","normal");
		});
		$("#minusF").click(function() {		
			sizeF = sizeF-10;
			$(".block .anons").css("font-size",sizeF+"%");
			$(".block .big-post").css("font-size",sizeF+"%");
			$(".block .big-post").css("line-height","normal");			
		});			

		$(".calendar .month a").click(function() {
			var Cleft = Math.floor($(".calendar").offset().left);
			var Ctop = Math.floor($(".calendar").offset().top);
			var CWleft = (Math.floor($(this).offset().left) + 20 - Cleft)+'px';
			var CWtop = (Math.floor($(this).offset().top)+10 - Ctop)+'px';
			var CWid = $(this).attr("rel");
			var cYear = $("#cYear option:selected").text();
			var cYearVal = $("select#cYear").val();
			$(".CLwindow").show().css('left',CWleft).css('top',CWtop);
			$(".CLwindow .monthname").html($(this).text());
			$.get("/calendar.php?year="+cYear+"&month="+CWid, function(data){
			$(".CLwindow .cont").html(data);
			});
			/*$(".CLwindow .bd .debug").html(cYear +' '+ cYearVal + ' '+ CWid);*/
		});
		$(".CLwindow .exit, .CLwindow .ok").click(function() {		
			$(this).parent().hide();
		})
		
	rotateAnonses = setInterval(rotateMain2, 5000);	
		function rotateMain() {
			var Photo = $(".block-main .photos .changer a.active ").attr("rel");
			$(".block-main .photos .ph1, .block-main .photos .ph2, .block-main .photos .ph3").hide();
			$(".block-main .photos ."+Photo).fadeIn('slow');
			$(".block-main .photos .changer .oph1, .block-main .photos .changer .oph2, .block-main .photos .changer .oph3").removeClass("active");
			$(".block-main .photos .changer .o"+Photo).addClass("active");
			$(".block-main  .texts.sph1, .block-main  .texts.sph2, .block-main  .texts.sph3").hide();
			$(".block-main  .texts.s"+Photo).fadeIn('slow');
			$(".block-main  .hph1, .block-main .hph2, .block-main .hph3").hide();
			$(".block-main  .h"+Photo).fadeIn('slow');
		}


    function rotateMain2() {
      var Photo = $(".block-main .photos .changer a.active ").attr("rel");
      changeAnons({"current":Photo});
    };

    $(".block-main .photos .changer a").click(function(){
        //clearInterval(rotateAnonses);
        var target = "ph" + ($(this).attr("rel").substring(2) - 1);
        if (target == "ph0"){
          target = "ph3";
        }
        changeAnons({"target":target});
        return false;
        });


		function changeAnons(o) {
			var currentPhoto = o.current || "1";
      var targetPhoto = o.target || currentPhoto;
			$(".block-main .photos .ph1, .block-main .photos .ph2, .block-main .photos .ph3").hide();

			$(".block-main .photos ."+targetPhoto).fadeIn('slow');

			$(".block-main .photos .changer .oph1, .block-main .photos .changer .oph2, .block-main .photos .changer .oph3").removeClass("active");
			$(".block-main .photos .changer .o"+targetPhoto).addClass("active");
			$(".block-main  .texts.sph1, .block-main  .texts.sph2, .block-main  .texts.sph3").hide();
			$(".block-main  .texts.s"+targetPhoto).fadeIn('slow');
			$(".block-main  .hph1, .block-main .hph2, .block-main .hph3").hide();
			$(".block-main  .h"+targetPhoto).fadeIn('slow');
		}

		
		var RZheight = $(".news-online .online-body").height();
		var RZcount = $(".news-online .online-body div").length - 1;
		var RZcurPX= 0;
		var RZpos = 0;
		
		var RZbodyheight = ($(".news-online .online-body div").eq(0).height())+($(".news-online .online-body div").eq(1).height())+($(".news-online .online-body div").eq(2).height())+25;		
		$('.news-online').css("height", RZbodyheight+'px' );
	setInterval(rotateRazd, 5000);	
		function rotateRazd() {
			if (RZcurPX+RZbodyheight-30 <= RZheight) {
			
			var RZcurN= $(".news-online .online-body div").eq(RZpos).height()+10;
			RZcurPX = RZcurPX + RZcurN; 
			
			$(".news-online .online-body").animate({ top: '-'+RZcurPX });
			RZpos++;
			}else{RZpos = 0; RZcurPX=0; }
		}
	
	   });
/*$(window).load(function(){

$(".slider-wrap").css('opacity','1');
	  });*/

