
$(function()
{
       /* $(document).shortkeys({

	   * @todo personnaliser les short keys

	  //'R':       function () { window.location.href=application_url+"/dir/add/"; },
	  'SpaceM':       function () { $('#try_me').append('M<br />'); },
	  'Space':   function () { $('#try_me').append('Space<br />'); },
	  'Space+V': function () { $('#try_me').append('Space+V<br />'); },
	  'V':       function () { $('#try_me').append('V<br />'); },
	  't+y':     function () { $('#try_me').append('T+Y<br />'); },
	  't+u':     function () { $('#try_me').append('T+U<br />'); }
	});*/
        $('#form_q').click (function() {
           $(this).attr('value', '');
        });
        $('.nyroModal').nyroModal();
        if ($.fn.tipTip)
        $("a,img,button,input,textarea").tipTip();
        $("a.multi").mullinx();
        var myMessages = ['info','notice','error','success'];
        hideAllMessages();
        if ($("#menu_options").length)
        oHandler = $("#menu_options").msDropDown({useSprite:'sprite'}).data("dd");

        // Show message
        for(var i=0;i<myMessages.length;i++)
        {
           showMessage(myMessages[i]);
        }

        // When message is clicked, hide it
        $('.message').click(function(){
           	$(this).animate({top: -$(this).outerHeight()}, 500);
         });
	$('#page .resource').each( function () {
             $(this).click( function () {
                var this_id = parse_id(($(this).attr('id')));
                $(this).attr('target', '_blank');
                if (this_id !=undefined)
                {
                    $.post(application_url+'controls/process/clic',
                    { resource_id: this_id},
                        function(data){
                            if (data == '1')
                                window.location.href = application_url+'dir/view/like/id/'+this_id
                            else if (data == '2')
                                window.location.href = application_url+'dir/view/unavailable/id/'+this_id
                        }
                    );
                }
            });
        });

        $('#page .favorite').each( function() {
            $(this).click( function () {
                var this_id = parse_id(($(this).attr('id')));

                $.post(application_url+'/controls/process/favorite',
                { resource_id: this_id},
                    function(data){
                        $('#messages').html(data);
                    }
                );
            });
        });
        $('#page .favdelete').each( function () {
            $(this).click( function () {
                var this_id = parse_id(($(this).attr('id')));
                $.post(application_url+'/controls/process/favdelete',
                { resource_id: this_id},
                    function(data){
                        $('#messages').html(data);
                    }
                );
            });
        });
        var section = new Array('span','#global_content','#global_content .item');
  	section = section.join(',');
	  // Reset Font Size
	  var originalFontSize = $(section).css('font-size');
	  $(".resetFont").click(function(){
	    $(section).css('font-size', originalFontSize);
	  });

	  // Increase Font Size
	  $(".increaseFont").click(function(){
	    var currentFontSize = $(section).css('font-size');
	    var currentFontSizeNum = parseFloat(currentFontSize, 10);
	    var newFontSize = currentFontSizeNum*1.2;
	    $(section).css('font-size', newFontSize);
	    return false;
	  });

	  // Decrease Font Size
	  $(".decreaseFont").click(function(){
	    var currentFontSize = $(section).css('font-size');
	    var currentFontSizeNum = parseFloat(currentFontSize, 10);
	    var newFontSize = currentFontSizeNum*0.8;
	    $(section).css('font-size', newFontSize);
	    return false;
  });


function formatItem(row) {
	return row[0];
}
function formatResult(row) {
	return row[0].replace(/(<.+?>)/gi, '');
}

function hideAllMessages()
{
    var messagesHeights = new Array(); // this array will store height for each

    for (i=0; i<myMessages.length; i++)
    {
        messagesHeights[i] = $('.' + myMessages[i]).outerHeight(); // fill array
        $('.' + myMessages[i]).css('top', -messagesHeights[i]); //move element outside viewport
    }
}

function showMessage(type)
{
    $('.'+ type +'-trigger').click(function(){
              hideAllMessages();
              $('.'+type).animate({top:"0"}, 500);
    });
}

  $("#form_q").autocomplete(application_url+'dir/search/suggestions', {
		width: 300,
		matchContains: true,
		scroll:true,
		minChars:3,
                autoFill:false
		//formatItem: formatItem,
		//formatResult: formatResult
	});
  $('#form_q').result(function(event, data, formatted) {
        $('#form_search').submit();
  });
$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav

	$("ul.topnav li span").click(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});



});

if (parent.frames.length > 0)
{
	window.top.location.href = location.href;
}

function parse_id(check_id)
{
     var a = check_id.split('_');
     var this_id = a[1];
     return this_id;
}

