// header image fade in/out effect
var header_images = new Array();
//header_images[0] = 'url(http://www.cientis.com/asset/images/content_header.jpg)';
//header_images[1] = 'url(http://www.cientis.com/asset/images/content_header_2.jpg)';
header_images[0] = 'url(http://www.cientis.com/asset/images/internal1.jpg)';
header_images[1] = 'url(http://www.cientis.com/asset/images/internal2.jpg)';
header_images[2] = 'url(http://www.cientis.com/asset/images/internal3.jpg)';
header_images[3] = 'url(http://www.cientis.com/asset/images/internal4.jpg)';
header_images[4] = 'url(http://www.cientis.com/asset/images/internal5.jpg)';
// ...
// keep adding images here if you want
header_image_index = 0;

jQuery.noConflict();
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' ) ); }
    } );

 } else {

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

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

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

  // initialize external links
  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' );

  // if carousel exists... preload carousel images
  if (typeof( window['aCarousel'] ) != 'undefined' && aCarousel.length) {
    for (var i in aCarousel) { jQuery.preloadImage( 'asset/upload/image/' + aCarousel[i].src ); }
  }

  jQuery( 'ul#menu' ).lavaLamp();

  jQuery("ul#listSubmenu li").hover(
    function () {
      jQuery(this).children("span.indicator").addClass("current");
    }, 
    function () {
      jQuery(this).children("span.indicator").removeClass("current");
    }
  );
  
  // text fade in/out effect
  setInterval(function(){
    jQuery('#quotes .slide').filter(':visible').fadeOut(1000,function(){
      if(jQuery(this).next('li.slide').size()){
        jQuery(this).next().fadeIn(1000);
      }
      else{
        jQuery('#quotes .slide').eq(0).fadeIn(1000);
      }
    });
  }, 15000);
  
  // header image randomize
  var randomnumber=Math.floor(Math.random()*5);
  jQuery('#heading_image').css('background-image', header_images[randomnumber]);
  
  // header image fade in/out effect
  /*
  setInterval(function(){
    jQuery('#heading_image').fadeOut(500,function(){
      header_image_index += 1;
      if (header_image_index >= header_images.length){
        header_image_index = 0;
      }
      jQuery(this).css('background-image', header_images[header_image_index]).fadeIn(1000);
    });
  }, 13000);
  */
});

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

var aCache = [];
jQuery.preloadImage = function() {

  var oImage = document.createElement( 'img' );
  for (var i = arguments.length; i--;) {
    oImage.src = arguments[i];
    aCache.push( oImage );
  }
}

function linkTo(optVal){
  if(optVal=="") return false;
  window.location='http://www.cientis.com/'+optVal;
}


