function thumbup(id,hash,table) {
var path;
path ="/ajax/thumbup/"+hash+"/"+table+"/"+id+"/";
$.post( path, { id: id, hash: hash, table: table },
 function(data){
   if(data.ok=='1') {
$('#thumbupcount').html(parseInt($('#thumbupcount').html())+1);

	 }
   //alert(data.name); // John
   //console.log(data.time); //  2pm
 }, "json");

}
function thumbdown(id,hash,table) {
	
var path;
path ="/ajax/thumbdown/"+hash+"/"+table+"/"+id+"/";
$.post( path, { id: id, hash: hash, table: table },
 function(data){
	 if(data.ok=='1') {
$('#thumbdowncount').html(parseInt($('#thumbdowncount').html())+1);	
 }
   //alert(data.name); // John
   //console.log(data.time); //  2pm
 }, "json");	

}

function getScrollY() {
    scrOfY = 0;
    if( typeof( window.pageYOffset ) == "number" ) {
        scrOfY = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        scrOfY = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        scrOfY = document.documentElement.scrollTop;
    }
    return scrOfY;
}

// emoticons

function emoticon(theSmilie)
{   
var tmp
tmp=$('#description').val();

$('#description').val(tmp+' '+theSmilie+' ');

}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function answer_post(id,user) {


//document.myForm.parentid.value="asd asd";
//document.getElementById('parentid').value ="asd asd";
$("#replytoview").html("@"+user);	
$("#parentid").val(id);	
$("#replyto").val("@"+user);
//asdasd=$("#parentid").val();
//alert(asdasd);
}

function clear() {

document.myForm.description.value ="";	
	} 

function setimage(handle) {
$("#current_slide").html(handle);
$("ul#galleryul li div").removeClass("pic-img-marked").addClass("pic-img");
$("#pic-img"+handle).removeClass("pic-img").addClass("pic-img-marked");

if ((handle==1)&&($("#novideo").val() != 1)) {

$("#images").css("visibility","hidden").css("width","0px").css("height","0px");	

setvideo();

}// video
else {


$("#video").html("").css("visibility","hidden").css("width","0px").css("height","0px");
$("#images").css("visibility","visible").css("width","357px").css("height","268px");
$("#imgageswap").attr("alt",$("#hidden-pic"+handle).attr("alt")).attr("src",$("#hidden-pic"+handle).attr("src")).css("opacity","0");

if($("#hidden-pic"+handle).attr("alt").length > 0) {
$("#image_info_holder").css("visibility","visible");
$("#image_info").html($("#hidden-pic"+handle).attr("alt"));
}else{
$("#image_info_holder").css("visibility","hidden");
}													  



}// not video


}

function fiximage(handle) {

var offset;

//$("#imgageswap").aeImageResize({ width: 357 , height: 2000 });	
$("#imgageswap").resize({maxWidth: 357});
offset=(268-$(handle).height())/2;
$("#imgageswap").css("position","absolute").css("left","0").css("top",offset).stop().animate({opacity:"1"}, 300);

	}

$(document).ready(function() { 

var tabContainers = $('div.tabs > div');
			tabContainers.hide().filter(':first').show();
			
			$('div.tabs ul.tabNavigation a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('div.tabs ul.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			}).filter(':first').click();
	
	
    var upprev_closed = false;
    var upprev_hidden = true;
    $(window).scroll(function() {
        var lastScreen = (getScrollY() + $(window).height() + 900) < $(document).height() * 1 ? false : true;
        if (lastScreen && !upprev_closed) {
            $("#upprev_box").stop().animate({right:"0px"}, 200);
            upprev_hidden = false;
        }
        else if (upprev_closed && getScrollY() == 0) {
            upprev_closed = false;
        }
        else if (!upprev_hidden) {
            upprev_hidden = true;
            $("#upprev_box").stop().animate({right:"-400px"}, 200);
        }
    });
    $("#upprev_close").click(function() {
        $("#upprev_box").stop().animate({right:"-600px"}, 200);
        upprev_closed = true;
        upprev_hidden = true;
    });

//topBar show/hide
	$(".hide_cp").click(function() {
        $(".top_bar_holder").stop().animate({top:"-40px"}, { "duration": "slow", "easing": "easeout" });
		$("#outerwrap").stop().animate({top:"-40px"}, { "duration": "slow", "easing": "easeout" });
		$("#myFloating_reg").addClass("offscreen");	
		$("#show_cp").stop().animate({top:"130px"}, { "duration": "slow", "easing": "bouncein" });
		
		if(navigator.appName == "Microsoft Internet Explorer"){
			$("body").stop().animate({backgroundPositionY:'-40px'}, { "duration": "slow", "easing": "easeout" });
		}else{
			$("body").stop().animate({backgroundPosition:'center -40px'}, { "duration": "slow", "easing": "easeout" });
		}
		
    });
	$("#show_cp").click(function() {
		$("#show_cp").stop().animate({top:"0px"}, { "duration": "slow", "easing": "bounceout" });
        $(".top_bar_holder").stop().animate({top:"0px"}, { "duration": "slow", "easing": "easeout" });
		
		$("#outerwrap").stop().animate({top:"0px"}, { "duration": "slow", "easing": "easeout" });
		$("#myFloating_reg").addClass("offscreen");
		
		if(navigator.appName == "Microsoft Internet Explorer"){
			$("body").stop().animate({backgroundPositionY:'0px'}, { "duration": "slow", "easing": "easeout" });
		}else{
			$("body").stop().animate({backgroundPosition:'center 0px'}, { "duration": "slow", "easing": "easeout" });
		}
		
    });



//carousel news gallery pics

$(function() {
    $(".n_photos_holder").jCarouselLite({
        btnNext: ".g_btn_next",
        btnPrev: ".g_btn_prev",
		visible: 3,
		easing: "easeout",
		circular: false,
		speed: 500
    });
});

$(function() {
    $(".carousel").jCarouselLite({
        btnNext: ".btn_next",
        btnPrev: ".btn_prev",
		easing: "easeout",
		circular: false,
		speed: 500
   });
});

 // opacity changes for the small pics of the main news		
		$(".pic-over").css({
				opacity: 0
			});
		$(".pic-over").hover(function() {
			$(this).stop().animate({
				opacity: 1
				}, 300);
			},function() {
			$(this).stop().animate({
				opacity: 0
				}, 300);
		});
		
$('.thumb_holder').hover(function(){
		$(".cover", this).stop().animate({top:'60px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'77px'},{queue:false,duration:160});
	});		
		
$(".g_btn_prev").click(function () {
var current;
var total;
var next;
current=parseInt($("#current_slide").html());
total =parseInt($("#total_slides").html());
next=current-1;
if (current>1) {setimage(next);}
else {}

});

$(".g_btn_next").click(function () {
var current;
var total;
var next;
current=parseInt($("#current_slide").html());
total =parseInt($("#total_slides").html());
next=current+1;
if (current<total) {setimage(next);}
else {}

});
// floating login box
	
    $("#login_btn").click(function () { 
        $("#myFloating_reg").removeClass("offscreen");
		$("#myFloating_reg").css({
				opacity:0
		});
		$("#myFloating_reg").stop().animate({
				opacity:1
		},500);
    });
	 $("#outerwrap").click(function(){
	    $("#myFloating_reg").addClass("offscreen");			
 	});
	 
	 $("#close_reg_form").click(function () {
		$("#myFloating_reg").addClass("offscreen");										  
	});
	 
// TWITTER FEED!

$(".tweet").tweet({
    join_text: "auto",
    username: ["novatv_bg", "Az_Obicham_BG"],
    count: 1,
    auto_join_text_default: "Нова ТВ:", 
    auto_join_text_ed: "Ние",
    auto_join_text_ing: "Бяхме",
    auto_join_text_reply: "Отговорихме",
    auto_join_text_url: "Разглеждахме",
    loading_text: "Зареждане..."
});




						   
});
