var fc_voting = {

    username:   null,
    user_id:    null,
    voteyn:		'x',
    /**
     * Oeffnen des Dialog-Overlay
     *
     * @param   integer  image_id
     * @param   integer  user_id
     * @since   01/2011
     * @version 01/2011
     */
    statDialog: function()
    {
        $('<div id="voting-dialog" />')
        .load('/bestphotographer/stat/1')
        .appendTo('body')
        .dialog({
            height: 900,
			width: 	800,
            modal: 	true,
            resizable: false,
            closeOnEscape: true,
            title: 	messages_voting['voting.title1'],
            buttons: {
                'schliesen': {
                    text: messages_default['dialog.buttonClose'],
                    click: function() {$(this).dialog("close").remove();}
                }
            },

            open: function() {
              // Wir setzen den Fokus auf den zweiten Button (Abbrechen)
              $(this).parents('.ui-dialog-buttonpane button:eq(1)').focus();
            }
        });
    },
    
    openDialog: function(username, user_id)
    {
        this.username	= username;
        this.user_id	= user_id;

        $('<div id="voting-dialog" />')
        .load('/bestphotographer/new/'+user_id)
        .appendTo('body')
        .dialog({
            height: 460,
            width: 	420,
            modal: 	true,
            resizable: false,
            closeOnEscape: false,
            title: 	messages_voting['voting.title1'],
            buttons: {
                'schliesen': {
                    text: messages_default['dialog.buttonClose'],
                    click: function() {$(this).dialog("close").remove();}
                }
            },

            open: function() {
              // Wir setzen den Fokus auf den zweiten Button (Abbrechen)
              $(this).parents('.ui-dialog-buttonpane button:eq(1)').focus();
            }
        });
    }, // openDialog
    
    openDialogParticipation: function()
    {
		var ua = window.navigator.userAgent.toLowerCase();
		
		if (ua.indexOf("msie 7.0") > -1)
		{
			var height = 390;
		}
		else
		{
			var height = 360;
		}
		

    	$('<div id="voting-dialog" />')
    	.load('/bestphotographer/self')
    	.appendTo('body')
    	.dialog({
    		height:	height,
    		width:	550,
    		modal:	true,
    		resizable: false,
            closeOnEscape: false,
    		title:	messages_voting['voting.title.participation'],
    		buttons :{
    			'Ja ich moechte teil nehmen.' : {
    				text : messages_voting['participate.yes'],
    				click: function() { fc_voting.participation("yes"); }
    				},
    			'Nein danke.' : {
    				text : messages_voting['participate.no'],
    				click: function() { fc_voting.participation("no");  }
    				},
    			'noch nicht.' : {
    				text : "Später entscheiden",
    				click: function() { fc_voting.participation("jain");  }
    				}
    		},
            open: function() {
              // Wir setzen den Fokus auf den zweiten Button (Abbrechen)
              $(this).parents('.ui-dialog-buttonpane button:eq(2)').focus();
            }
    	});
    }, // openDialogParticipation
    
    participation: function(status)
    {
    	if(status == 'jain')
    	{
    		fc_voting.ASParticipation('Du kannst dich jederzeit in deinem Profil entscheiden.');
    	}
    	else
    	{
			$.ajax({
				url:		'/bestphotographer/participation/'+status,
				type:		'GET',
				success:	fc_voting.ASParticipation,
				error:		fc_voting.ajaxError,
				data:		{}
			});
		}
    },
    
    ASParticipation: function(content)
    {
    	if(content != 'Du kannst dich jederzeit in deinem Profil entscheiden.')
    	{
    	 	$("#bestphotographer_link").text(content);
    	}
    	
        $("#voting-dialog").dialog("close").remove();
        
         $('<div id="voting-dialog" />')
    	.text(content)
    	.appendTo('body')
    	.dialog({
    		height:	150,
    		width:	350,
    		modal:	true,
    		resizable: false,
            closeOnEscape: false,
    		title:	messages_voting['voting.title.participation'],
            buttons: {
                'schliesen': {
                    text: messages_default['dialog.buttonClose'],
                    click: function() {$(this).dialog("close").remove();}
                }
            },
            open: function() {
              // Wir setzen den Fokus auf den zweiten Button (Abbrechen)
              $(this).parents('.ui-dialog-buttonpane button:eq(1)').focus();
            }
    	});	
    },
   

    vote: function(status)
    {
    	$.ajax({
	   		url:     '/bestphotographer/getvoting/'+fc_voting.user_id+'/'+status,
   		    type:    'GET',
   		    success: fc_voting.ASVote,
   		    error:   fc_voting.ajaxError,
   		    data:    {}
		    });
    },

    ASVote: function(content)
    {
    	$("#bestphotographer_link").text(content);
        $("#voting-dialog").dialog("close").remove();
    },

 ajaxError: function(XMLHttpRequest)
    {
      alert(XMLHttpRequest.responseText);
    }
};
