jQuery( document ).ready( function () {
  // if working locally...
  if (jQuery( 'base' ).exists() && jQuery( 'base' ).attr( 'href' ).match( '127.0.0.1' )) {

    var sPath = jQuery( 'base' ).attr( 'href' ).replace( /\/application\/.+\//, '' );

    // prepend absolute links with (abbreviated) local path
    jQuery( 'a[href^=/]' ).each( function () { jQuery( this ).attr( 'href', sPath + jQuery( this ).attr( 'href' ) ); } );

    // prepend form actions with (abbreviated) local path
    jQuery( 'form' ).each( function () {
      if (jQuery( this ).attr( 'action' ).match( /^\// )) { jQuery( this ).attr( 'action', sPath + jQuery( this ).attr( 'action' ) ); }
    } );
	}

  // remove focus border
  jQuery( 'a' ).focus( function () { this.blur(); } );

  // remove focus border
  jQuery( 'a.external' ).click( function () {
    window.open( jQuery( this ).attr( 'href' ) );
    return false;
  } );

  // assign name (to avoid: id="txtFoo" name="txtFoo")
  jQuery( 'form :input[id]' ).each( function () {
    if (jQuery( this ).attr( 'name' ) == '' || jQuery( this ).attr( 'name' ) == null) {
      jQuery( this ).attr( 'name', jQuery( this ).attr( 'id' ) );
    }
  } );

  // remove textarea resize (for safari)
  jQuery( 'textarea' ).css( 'resize', 'none' );

   ///// show submenu when click to main menu item /////

	 jQuery( 'ul#mainMenuList a.mainMenu' ).click( function () {
	
		 if (jQuery( this ).hasClass( 'home' )) {
       window.location("http://metprinters.com/");
		 }
		 
		 var oElement = jQuery( this ).siblings( 'ul' );
	
					 
		 if (oElement.hasClass( 'closed' )) {
			 jQuery( 'ul#mainMenuList ul.subMenu' ).slideUp( 'fast' );
			 jQuery( 'ul#mainMenuList ul.subMenu' ).removeClass( 'open' ).addClass( 'closed' );
			 oElement.removeClass( 'closed' ).addClass( 'open' );
			 oElement.slideDown( 'fast' );
		 } else {
			 oElement.removeClass( 'open' ).addClass( 'closed' );
			 oElement.slideUp( 'fast' );
		 }

		 return false;
	
	 } );
  //// when open blog open the our company menu	 
	 jQuery( 'ul#mainMenuList ul.open' ).slideDown( 'fast' );

  // initialize menu
  jQuery( 'ul.menu li.current' ).closest( 'ul' ).show();
  jQuery( 'ul.menu li.current' ).find( 'ul:first' ).show();

  // initialize textsize
  jQuery( 'div.textsize a.plus' ).click( function ()  { setTextSize( 'plus' ); return false; } );
  jQuery( 'div.textsize a.minus' ).click( function () { setTextSize( 'minus' ); return false; } );

  // initialize global search
  jQuery( 'div#divButton_Search' ).click( function () { jQuery( this ).closest( 'form' ).submit(); } );

  // initialize calendar
  jQuery( 'div#divDatepicker' ).datepicker( {

    inline: true,

    beforeShowDay: function ( oDate ) {

      if (aEvent != null) {

        for (i = 0; i < aEvent.length; i++) {
          var aDate = aEvent[i].split( '-' );
          if (oDate.getFullYear() == aDate[0] &&
              oDate.getMonth()    == aDate[1] - 1 &&
              oDate.getDate()     == aDate[2]) {
            return [ true, '' ];
          }
        }

        return [ false, '' ];
      }
    },

    onSelect: function( sDate ) {

      var aDate = sDate.split( '/' );
      document.location = jQuery( 'base' ).attr( 'href' ).replace( /application.+/, '' ) + 'helpful-stuff/event-calendar/' + aDate[2] + '-' + aDate[0] + '-' + aDate[1];
    }

  } );

} );

/*
 * Custom jQuery methods
 */
jQuery.fn.exists = function() { return jQuery( this ).length > 0; }


function displayMediaPlayer( sURL , nPageID, sPlayerName ) {

  var oCONSTANT = { BASE        : jQuery( 'base' ).attr( 'href' ) + 'asset/media/swf/',
                    SWF         : sPlayerName,
                    BGCOLOR     : '#FFFFFF',
                    WIDTH       : 798,
                    HEIGHT      : 449,
                    PATH        : '/_page_xml',
                    IMAGE_DELAY : sURL.match( 'home' ) ? 10 : 6 };

  var sParam = '<param name="allowScriptAccess" value="sameDomain" />'
             + '<param name="allowFullScreen" value="false" />'
             + '<param name="bgcolor" value="' + oCONSTANT.BGCOLOR + '" />'
             + '<param name="base" value="'    + oCONSTANT.BASE    + '" />'
             + '<param name="menu" value="false" />'
             + '<param name="quality" value="high" />'
             + '<param name="wmode" value="transparent" />'
             + '<param name="allowFullScreen" value="showall" />'
             + '<param name="align" value="middle" />'             
             + '<param name="scale" value="false" />'             
             + '<param name="FlashVars" value="url=' + jQuery( 'base' ).attr( 'href' ) + sURL.replace( /^\//, '' ) + oCONSTANT.PATH +'/'+ nPageID  + '&image_delay=' + oCONSTANT.IMAGE_DELAY + '" />';

  var sHTML  = '<div>'
             +   '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + oCONSTANT.WIDTH + '" height="' + oCONSTANT.HEIGHT + '">'
             +     '<param name="movie" value="' + oCONSTANT.BASE + oCONSTANT.SWF + '.swf?nocache=' + new Date().getTime() + '" />'
             +     sParam
             + '<!--[if !IE]>-->'
             +     '<object type="application/x-shockwave-flash" data="' + oCONSTANT.BASE + oCONSTANT.SWF + '.swf?nocache=' + new Date().getTime() + '" width="' + oCONSTANT.WIDTH + '" height="' + oCONSTANT.HEIGHT + '">'
             +        sParam
             + '<!--<![endif]-->'
             +       '<a href="http://www.adobe.com/go/getflashplayer" class="external"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a>'
             + '<!--[if !IE]>-->'
             +     '</object>'
             + '<!--<![endif]-->'
             +   '</object>'
             + '</div>';

  document.write( sHTML );
}

function displayVideo( oData ) {

  var aEntry = oData.feed.entry || [];

  if (aEntry.length) {
    var oVideo = aEntry.shift();
    swfobject.embedSWF( oVideo.media$group.media$content[0].url + '&rel=1&border=0&fs=1&autoplay=0', 'objYouTubePlayer', '190', '140', '9.0.0', false, false, { allowfullscreen : 'true' } );
  }
}



