var canLoad = true;

$(window).load( function() {
  if( !canLoad )
    return;
    
  /* IE6 transparent .png */
  if( isOldIE() )  {
    $('#content').supersleight();
    $('#product-image').supersleight({shim: theme_path() + 'img/transparent.gif'});
    //$('#portfolio-list').supersleight({shim: theme_path() + 'img/transparent.gif'});
  }
  
  //$('body').supersleight();
  //$('#info').supersleight();
  /* IE6 */
  
  /* IE6 */
  if( isOldIE() )
    $('a.graphic').hover(
      function() {
        if( !$(this).is('.active') ) {
          $(this).find('img.normal').hide();
          $(this).find('img.hover').show();
        }
      },
      function() {
        if( !$(this).is('.active') ) {
          $(this).find('img.hover').hide();
          $(this).find('img.normal').show();
        }
      }
    );
  
  
  $('#page-content').css( 'visibility', 'visible' );
  $('#loading-container').css( 'visibility', 'hidden' );

  $(window).resize();
  
  showLayer( 'page-main' );
})

function isOldIE() {
  return (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4);
}

function isIE() {
  return jQuery.browser.msie;
}

// Get elements with given tag and class.
function hasClass (obj, className) {
  if (typeof obj == 'undefined' || obj==null || !RegExp) { return false; }
  var re = new RegExp("(^|\\s)" + className + "(\\s|$)");
  if (typeof(obj)=="string") {
    return re.test(obj);
  }
  else if (typeof(obj)=="object" && obj.className) {
    return re.test(obj.className);
  }
  return false;
}

// Get elements with given tag and class.
function getElements( tag, className, parent ) {
  if( className == null )
    className = '';

  if( parent == null )
    parent = document;

  var objs = parent.getElementsByTagName( tag );
  var arr = Array();
  
  for(i=0; i < objs.length; i++) {
    if( className=='' || hasClass(objs[i], className) ) {
      arr.push( objs[i] );
    }
  }
  
  return arr;
}

function jqueryGetElements( tag, className, parent ) {
  var obj = getElements( tag, className, parent );
  var arr = Array();
  
  for( i in obj )
    arr.push( $('#'+obj[i].id) );
  
  return arr;
}

// Centrowanie w pionie i/lub poziomie.
function centerElement( obj, horizontal, vertical ) {
  var h = obj.parent().height();
  var w = (obj.parent().width() - obj.width()) / 2;

 
  /* IE6 Always height==0 */
  if( obj.parent().attr('id') == 'page-main' )
    h = $(document).height();
  /* IE6 */

  h = (h - obj.height()) / 2;
  if( h < 0 ) h = 0;
  if( w < 0 ) w = 0;
  
  if( horizontal )
    obj.css({ 'left': w });
  if( vertical )
    obj.css({ 'top': h });
}

// Center elements with class 'center'.
function centerElements() {
  var tags=new Array( 'div', 'ul', 'a' );
  var horiz=false, vert=false;
  var obj;
  
  for( var tag_i=0; tag_i<=2; tag_i++) {
  
    $(tags[tag_i]).each(function(index){
      obj = $(this);
      
      horiz = obj.is('.center-horizontal');
      vert = obj.is('.center-vertical');
      if( obj.is('.center') ) {
        horiz = true;
        vert = true;
      }

      if( horiz || vert ) {
        centerElement( obj, horiz, vert );
      }
    });
  }

  return;
}


function t( s ) {
  if( getLang() == 'en' )
    return s;
  
  if( getLang() == 'pl' ) {
    if( s=='Continue') return 'Dalej';
  }
}
