$(document).ready(function() {
    // console.log($('.shadow'));
    // $('.shadow').dropShadow({color: '#ff0000', opacity: 1});
    });
function vote(idParam, vote, controlsId) {
    $.getJSON("/vote/vote.jsp",
    {
        type: 'media',
        id: idParam,
        vote: vote
    },
    function(json){
        if (json.message == 0 ) window.location = '/users/loginForm.jsf';
        $('#'+controlsId+' .voteMe').html('Glasova: '+json.votes);
        $('#'+controlsId+' .infomsg').html(json.message);
        $('#'+controlsId+' .infomsg').show();
        setTimeout("$('#"+controlsId+" .infomsg').hide()", 2000);
    }
    );
}
function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
};

function refreshMovie(that){
    
    videoInfo(that);
    getFlashMovie("bjsa").promeni(videoItems[that].servletPath, videoItems[that].imgMedValue);

};
function videoInfo (that) {
    $('#videoDesc span').html( videoItems[that].date );
    $('#videoDesc h1 a').attr('href', videoItems[that].hrefValue );
    $('#videoDesc h1 a').html(videoItems[that].caption);
    $('#videoDesc h2 a').attr('href', videoItems[that].userHrefValue );
    $('#videoDesc h2 a').html(videoItems[that].userFullName);
    $('#videoControls .komentari').attr('href', videoItems[that].hrefValue + '#comments' );
    $('#videoControls .voteUp').attr('href', 'javaScript:vote("'+ videoItems[that].id +'","up")' );
    $('#videoControls .voteDown').attr('href', 'javaScript:vote("'+ videoItems[that].id +'","down")' );
    
    if(videoItems[that].votingAllowed == "true") {
        $('#videoListVoteUp').attr('href', 'javaScript:vote("'+ videoItems[that].id +'","up","videoControls")' );
        $('#videoListVoteUp').attr('class', 'voteUp');
        $('#videoListVoteUp').attr('title', 'Glasajte za');
        $('#videoListVoteDown').attr('href', 'javaScript:vote("'+ videoItems[that].id +'","down","videoControls")' );
        $('#videoListVoteDown').attr('class', 'voteDown');
        $('#videoListVoteDown').attr('title', 'Glasajte protiv');
    } else {
        $('#videoListVoteUp').attr('href', 'javaScript:;' );
        $('#videoListVoteUp').attr('class', 'voteUpGray');
        $('#videoListVoteUp').attr('title', 'Glasanje završeno');
        $('#videoListVoteDown').attr('href', 'javaScript:;' );
        $('#videoListVoteDown').attr('class', 'voteDownGray');
        $('#videoListVoteDown').attr('title', 'Glasanje završeno');
    }
}
function changeImage (that) {
    $('#mainPic').attr('src', photoItems[that].imgMedValue );
    $('.photoImage a').attr('href', photoItems[that].hrefValue );
    $('#photoDesc span').html( photoItems[that].date );
    $('#photoDesc h1 a').attr('href', photoItems[that].hrefValue );
    $('#photoDesc h1 a').html(photoItems[that].caption);
    $('#photoDesc h2 a').attr('href', photoItems[that].userHrefValue );
    $('#photoDesc h2 a').html(photoItems[that].userFullName);
    $('#photoControls .komentari').attr('href', photoItems[that].hrefValue + '#comments' );
    
    if(photoItems[that].votingAllowed == "true") {
        $('#photoListVoteUp').attr('href', 'javaScript:vote("'+ photoItems[that].id +'","up","photoControls")' );
        $('#photoListVoteUp').attr('class', 'voteUp');
        $('#photoListVoteUp').attr('title', 'Glasajte za');
        $('#photoListVoteDown').attr('href', 'javaScript:vote("'+ photoItems[that].id +'","down","photoControls")' );
        $('#photoListVoteDown').attr('class', 'voteDown');
        $('#photoListVoteDown').attr('title', 'Glasajte protiv');
    } else {
        $('#photoListVoteUp').attr('href', 'javaScript:;' );
        $('#photoListVoteUp').attr('class', 'voteUpGray');
        $('#photoListVoteUp').attr('title', 'Glasanje završeno');
        $('#photoListVoteDown').attr('href', 'javaScript:;' );
        $('#photoListVoteDown').attr('class', 'voteDownGray');
        $('#photoListVoteDown').attr('title', 'Glasanje završeno');
    }
};

function changeContestImage (that) {
    $('#mainPic').attr('src', photoItems[that].servletPath );
    $('.photoImage a').attr('href', photoItems[that].hrefValue );
    $('#photoDesc span').html( photoItems[that].date );
    $('#photoDesc h1 a').attr('href', photoItems[that].hrefValue );
    $('#photoDesc h1 a').html(photoItems[that].caption);
    $('#photoDesc h2 a').attr('href', photoItems[that].userHrefValue );
    $('#photoDesc h2 a').html(photoItems[that].userFullName);
    $('#photoControls .komentari').attr('href', photoItems[that].hrefValue + '#comments' );
    
    if(photoItems[that].votingAllowed == "true") {
        $('#photoListVoteUp').attr('href', 'javaScript:vote("'+ photoItems[that].id +'","up","photoControls")' );
        $('#photoListVoteUp').attr('class', 'voteUp');
        $('#photoListVoteUp').attr('title', 'Glasajte za');
        $('#photoListVoteDown').attr('href', 'javaScript:vote("'+ photoItems[that].id +'","down","photoControls")' );
        $('#photoListVoteDown').attr('class', 'voteDown');
        $('#photoListVoteDown').attr('title', 'Glasajte protiv');
    } else {
        $('#photoListVoteUp').attr('href', 'javaScript:;' );
        $('#photoListVoteUp').attr('class', 'voteUpGray');
        $('#photoListVoteUp').attr('title', 'Glasanje završeno');
        $('#photoListVoteDown').attr('href', 'javaScript:;' );
        $('#photoListVoteDown').attr('class', 'voteDownGray');
        $('#photoListVoteDown').attr('title', 'Glasanje završeno');
    }
};

function changeTImage (that, homePartId) {
    $('#mainTPic'+homePartId).attr('src', topListItems[homePartId][that].imgMedValue );
    $('#photoImageTop'+homePartId+' a').attr('href', topListItems[homePartId][that].hrefValue );
    $('#photoImageTop'+homePartId+' a').attr('title', topListItems[homePartId][that].caption);
    $('#homeRang').html(topListItems[homePartId][that].rank);
    $('#mediaType').attr('src', '/img/'+topListItems[homePartId][that].type+'.png' );
    $('#mediaType').attr('alt', topListItems[homePartId][that].type );
    $('#listaKontole span').html( topListItems[homePartId][that].date );
    $('#listaKontole h1 a').attr('href', topListItems[homePartId][that].hrefValue );
    $('#listaKontole h1 a').html(topListItems[homePartId][that].caption);
	$('#naslov'+homePartId).html(topListItems[homePartId][that].caption);
	$('#listaKontole h2 a').attr('href', topListItems[homePartId][that].userHrefValue );
    $('#listaKontole h2 a').html(topListItems[homePartId][that].userFullName);
    $('#listaControls .komentari').attr('href', topListItems[homePartId][that].hrefValue + '#comments' );
    if(topListItems[homePartId][that].votingAllowed == "true") {
        $('#topListVoteUp').attr('href', 'javaScript:vote("'+ topListItems[homePartId][that].id +'","up","listaControls")' );
        $('#topListVoteUp').attr('class', 'voteUp');
        $('#topListVoteUp').attr('title', 'Glasajte za');
        $('#topListVoteDown').attr('href', 'javaScript:vote("'+ topListItems[homePartId][that].id +'","down","listaControls")' );
        $('#topListVoteDown').attr('class', 'voteDown');
        $('#topListVoteDown').attr('title', 'Glasajte protiv');
    } else {
        $('#topListVoteUp').attr('href', 'javaScript:;' );
        $('#topListVoteUp').attr('class', 'voteUpGray');
        $('#topListVoteUp').attr('title', 'Glasanje završeno');
        $('#topListVoteDown').attr('href', 'javaScript:;' );
        $('#topListVoteDown').attr('class', 'voteDownGray');
        $('#topListVoteDown').attr('title', 'Glasanje završeno');
    }
    $('#topListVotes').html('Glasova: '+topListItems[homePartId][that].votes);
    $('#topListCommentCount').html('Komentara: '+topListItems[homePartId][that].comments);
};
