$(document).ready(function(){

    $("#menu table td").mouseover(function() {
       $(this).children('.light').css({opacity: 0.5});
    });

    $("#menu table td").mouseout(function() {
       $(this).children('.light').css({opacity:1});
    });

    $(".block").hide();
    $("#help .title").click(function(){
		$(this).toggleClass("block").next().slideToggle(200);
	});

    $('#list tr:even').addClass('even');
    $('#list tr:odd').addClass('odd');
    $('#list tr').hover(
        function(){
            $(this).toggleClass('highlight');
        },
        function(){
            $(this).toggleClass('highlight');
        }
    )

    $("#header").click(function() {
       window.location = 'http://mojo.bg/home/'
    });

   $("#header").mouseover(function() {
        $(this).addClass("cursor");
   });

   $("#header").mouseout(function() {
        $(this).removeClass("cursor");
   });

   $("#messageForm").focus(function() {
        $(this).addClass("focusField");
   });

   $("#messageForm").blur(function() {
        $(this).removeClass("focusField");
   });

   $(".button70").mouseover(function() {
        $(this).addClass("button70_mo");
   });

   $(".button70").mouseout(function() {
        $(this).removeClass("button70_mo");
   });

   $(".button90").mouseover(function() {
        $(this).addClass("button90_mo");
   });

   $(".button90").mouseout(function() {
        $(this).removeClass("button90_mo");
   });

   $(".button120").mouseover(function() {
        $(this).addClass("button120_mo");
   });

   $(".button120").mouseout(function() {
        $(this).removeClass("button120_mo");
   });

   $(".image_button").mouseover(function() {
        $(this).addClass("image_button_mo");
   });

   $(".image_button").mouseout(function() {
        $(this).removeClass("image_button_mo");
   });
   
   $('.upform').submit(function(eve) {
       eve.preventDefault();
       var image_Id = $(this).find("input[name='imageId']").val();
       var user_Id = $(this).find("input[name='userId']").val();

       $.post('/profile/vote/',{userId: user_Id, imageId: image_Id},
        function(html) {
            if(parseFloat(html)){
		 		$("#img" + image_Id).text(html);
		 	} else {
		 		alert(html);
		 	}
       });
   });

   $('#sendRequest').submit(function(eve) {
       eve.preventDefault();
       var remoteUser_Id = $(this).find("input[name='remoteUserId']").val();

       $.post('/profile/friendshipRequest/',{remoteUserId: remoteUser_Id},
        function(html) {
            $('#status').text(html).show(300);
       });
   });

   $('#selected').click(function() {selectAllText($(this))});


   function selectAllText(textbox)
   {
        textbox.focus();
        textbox.select();
   }


   var mojoTitle = document.title;
   setInterval(unreadMessages,15000);
   function unreadMessages()
   {
       $.post('/home/existUnreadMessages/',{},
            function(html) {
                if(html != 0) {
                    t = setInterval(function(){
                        document.title = html;
                        setTimeout(function(){
                            document.title = mojoTitle;
                            },750);
                    },1500);
                } else {
                    if(typeof(t) != 'undefined') {
                        clearInterval(t);
                        document.title = mojoTitle;
                    }
                }
           });
   }

   //home page game images
//   setInterval(gameImages,8000);
   var key = true;

   function gameImages()
   {
        if(key){
            $('#mostExpensiveImages').load("home/expensiveVoteImages/");
            key = false;
        } else {
            $('#mostExpensiveImages').load("home/dailyVoteImages/");
            key = true;
        }
   }
});

function conversationChangeBg(mouseevent,number,id)
{
    if (id != 'conversationImage')
        {
            if (mouseevent=="mouseover")
                {
                    document.getElementById('conversationNewMessages'+number).className = "conversationCellMouseOverText";
                    document.getElementById('conversationNames'+number).className = "conversationCellMouseOverText";
                    document.getElementById('conversationAge'+number).className = "conversationCellMouseOverText";
                    document.getElementById('conversationDate'+number).className = "conversationCellMouseOverText";
                }
            else if (mouseevent=="mouseout")
                {
                    document.getElementById('conversationNewMessages'+number).className = "conversationCell";
                    document.getElementById('conversationNames'+number).className = "conversationCell";
                    document.getElementById('conversationAge'+number).className = "conversationCell";
                    document.getElementById('conversationDate'+number).className = "conversationCell";
                }
        }
    else
        {
            if (mouseevent=="mouseover")
                {
                    document.getElementById('conversationImage'+number).className = "conversationCellMouseOverImage";
                }
            else if (mouseevent=="mouseout")
                {
                    document.getElementById('conversationImage'+number).className = "conversationCell";
                }
        }
}

