/*
     Onirica Template
     File: global.js
     Stefano Giliberti - kompulsive@gmail.com clickswitch.net
*/

$(document).ready(function(){
     /* A little trick that removes the divisor background on the last element of the navigation menu */
     $("#navigation ul li:last-child").css('background','none');

     /* Search label */
     htmlinput = $("#navigation input").val() /* picks the inital value of the input (in the html) */
     $("#navigation input").css('color','#b3b3b3').css('font-style','italic');
     $("#navigation input").focus(function(){ /* on focus.. */
          curinput = $(this).val() /* picks the -current- value */
          if(curinput == htmlinput){ /* if the current value corresponds to the initial value (htmlinput var) */
               $(this).val(''); /* empty the input */
               $(this).css('color','#666').css('font-style', 'normal').css('text-align', 'left');
          }
     });
     $("#navigation input").blur(function(){ /* on blur */
          curinput = $(this).val();
          if(curinput == ''){ /* if the current value is null .. */
               $(this).css('color','#b3b3b3').css('font-style','italic');
               $(this).val(htmlinput); /* sets the value with its inital value (htmlinput var) */
          }
     });

     // Remove ugly borders from links, buttons, etc. when they are clicked
     $('a, button').focus(function() {
          $(this).blur();
     });

     // Force external links and links to PDF file to load in a new window
     // (note: you should still add "target='_blank'" to these links, but
     // this code will catch any such links that may have been overlooked)
     $('a[href^="http:"]').attr('target', '_blank');
     $('a[href$=".pdf"]').attr('target', '_blank');

     // Add classes to attach filetype icons to corresponding filetypes
     $('a[href$=".pdf"]').addClass('PDF');

     // Fix the IE buggy behavior of scrolling the background image of the <input> element
     // out of view when the content of the field overflows (i.e. user types too much)
     // its dimensions
     if($.browser.msie && $.browser.version=='7.0') {     // see if browser is IE & version is 7.0
          $("input.text, #navigation input").click(
               function () { //solve IE BG image bug partially
               $(this).css("background-position","100% 0");
          }).blur(
               function(){
                $(this).css("overflow","hidden");
                        // $(this).css("background-position","0 0");
          });
     }

     // Give users a way to close any informational messages that are displayed periodically.
     if ($('div#msg').is(':visible')) {
          var $hideMe = $('<div id="hideMe">Hide this<img src="/images/hide-icon.gif" width="7" height="7" border="0" style="margin-left: 0.5em;"/></div>')
                              .css({
                                        position: 'absolute',
                                        top: '1em',
                                        right: '1em',
                                        padding: 0,
                                        margin: 0,
                                        cursor: 'pointer',
                                        fontSize: '10px',
                                        lineHeight: '10px',
                                        color: '#c8b875'
                                   })
                              .appendTo($('div#msg'));
          $hideMe.bind('click', function() {
               $('div#msg').fadeOut(200);
          });
     }
});
