
function openCommentForm(){
    $('.comment-form-wrap').show();
}

function makeVote(t, i){
    $.get("/bg/charts/vote/makevote", {type:t, label:i} , function(data){
        if(data.success){
            alert(data.msg);
        }else{
            alert(data.msg);
        }
    }, "json");
}
function openVideoModal(title, url){
    $("#modal-video").attr("title", title);
    $( "#modal-video" ).dialog({
	autoOpen: true,
	height: 400,
	width: 650,
	modal: true
    });
    $("#modal-video").html("<object width='620' height='355' id='flvPlayer'><param name='allowFullScreen' value='true'><embed src='/osplayer/OSplayer.swf?movie="+url+"&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=on&vTitle=&showTitle=yes' width='620' height='355' allowFullScreen='true' type='application/x-shockwave-flash' allowScriptAccess='always'></object>");
}

var artistListIndex = 0;

function artistListNext(){
    
    if((artistListIndex - 960)*-1 <= ($(".header-artists-items > a").length*190)){
        artistListIndex -= 950;
        $(".header-artists-items").animate({"margin-left":artistListIndex+"px"}, 1000);
        return true;
    }
    return false;
}

function artistListPrev(){
    if(artistListIndex+950 <= 0){
        artistListIndex += 950;
        $(".header-artists-items").animate({"margin-left":artistListIndex+"px"}, 1000);
        return true;
    }
    return false;
}

function artistListFirst(){
    $(".header-artists-items").animate({"margin-left":"0px"}, 1000);
    artistListIndex = 0;
    return true;
}

function autoArtistList(){
    if(!artistListNext()) artistListFirst();
    artistListTimer = setTimeout(autoArtistList, 5000);
}

function showRecaptcha(element) {
    Recaptcha.create("6Ld5UssSAAAAAPXkqIhzrzkfEcG38foVt1wveZk0", element, {
        lang: "en",
        callback: Recaptcha.focus_response_field
    });
}

function verifyRecaptcha(){
    $.get("/comment/verifycaptcha",
        {recaptcha_challenge_field: Recaptcha.get_challenge(), recaptcha_response_field: Recaptcha.get_response()},
        function(data){
            if(data == 1){

            }else{
                Recaptcha.reload();
                Recaptcha.focus_response_field();
            }
        }
    );
}

function sendComment(){
    $(".comment-form-wrap").RemoveBubblePopup();
    $.post("/comment/new",
        $(".comment-form-wrap").serialize(),
        function(data){
            var res = jQuery.parseJSON(data);
            if(res.success){
                $(".comments-list-wrap").CreateBubblePopup({
                    position : 'top',
                    align: 'center',
                    innerHtml: "Вашият коментар беше успешно добавен!",
                    innerHtmlStyle: {
                        color:'#FFFFFF',
                        'text-align':'center'
                    },
                    themeName: 	'all-green',
                    themePath: 	'/interface/jquerybubblepopup-theme',
                    alwaysVisible: true,
                    manageMouseEvents: false
                });

                $(".comments-list-wrap").prepend('<tr><td valing="top" align="center" width="25%"><b>'+res.item.userName+"</b><br />"+res.item.createdAt+'</td><td>'+res.item.comment+'</td></tr>');

                $(".comments-list-wrap").ShowBubblePopup();
                Recaptcha.reload();
            }else{
                $(".comment-form-wrap").CreateBubblePopup({
                    position : 'top',
                    align: 'center',
                    innerHtml: "Моля, попълнете формата коректно!",
                    innerHtmlStyle: {
                        color:'#FFFFFF',
                        'text-align':'center'
                    },
                    themeName: 	'all-red',
                    themePath: 	'/interface/jquerybubblepopup-theme',
                    alwaysVisible: true,
                    manageMouseEvents: false
                });
                $(".comment-form-wrap").ShowBubblePopup();


                Recaptcha.reload();
                Recaptcha.focus_response_field();
            }
        },
        function(){
            Recaptcha.reload();
            Recaptcha.focus_response_field();
        }
    );

}

var comments = 0;
var currentComments = 0;
function loadComments(){
    $.get(
        "/comment/load",
        {t: $("#commentType").val(), i: $("#commentObj").val(), s: 0},
        function(res){
            if(res.success){
                $.each(res.items, function(i, v){
                    $(".comments-list-wrap").append('<tr><td valing="top" align="center" width="25%"><b>'+v.userName+"</b><br />"+v.createdAt+'</td><td>'+v.comment+'</td></tr>');
                });
            }
            $(".total-comments").html("Коментари: "+res.count);
        },
        "json"
    );
}
/*
$(document).ready(function(){
    $.get(
        "/bg/index/background/load",
        function(res){
            if(res.success){
                $("body").append('<img id="bgimage" src="'+res.image+'" border="0" alt="" />');
            }
        },
        "json"
    );    
});
*/

$(document).ready(function(){
    $("body").append('<img id="bgimage" src="/interface/15-godini-background.jpg" border="0" alt="" />');
});

var tvitems;
var currentTvItem = 0;

function nextTvItem(){
    if( (currentTvItem+1) < tvitems.length ){
        $(tvitems[currentTvItem]).fadeOut(1000);
        $(tvitems[currentTvItem+1]).fadeIn(500, function(){ setTimeout(nextTvItem, 5000)});
        currentTvItem++;
    }else{
        $(tvitems[currentTvItem]).fadeOut(1000);
        $(tvitems[0]).fadeIn(500, function(){ setTimeout(nextTvItem, 5000)});
        currentTvItem = 0;
    }
}
