// JavaScript Document Ver. 1.0 (11.08.2008)


// styleswither
//======================================================================================================

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  //setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


// fixPNG(); (author Tigirlas Igor)
//======================================================================================================

function fixPNG(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
    if (element.tagName=='IMG')
    {
    if (/\.png$/.test(element.src))
    {
    src = element.src;
    element.src = "/img/blank.gif";
    }
  }
  else
  {
    src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
    if (src)
    {
    src = src[1];
    element.runtimeStyle.backgroundImage="none";
    }
  }
  if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
  }
}

function fixPNGAbsolute(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
    if (element.tagName=='IMG')
    {
    if (/\.png$/.test(element.src))
    {
    src = element.src;
    element.src = "/img/blank.gif";
    }
  }
  else
  {
    src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
    if (src)
    {
    src = src[1];
    element.runtimeStyle.backgroundImage="none";
    }
  }
  if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='image')";
  }
}



//layout switcher
//======================================================================================================

// Dynamically change layout based on window sized
// Based on work by Simon Collison et al
// http://www.collylogic.com/?/comments/redesign-notes-1-width-based-layout/


wraphandler = {
  init: function() {
    if (!document.getElementById) return;
    // set up the appropriate wrapper
    wraphandler.setWrapper();
    // and make sure it gets set up again if you resize the window
    wraphandler.addEvent(window,"resize",wraphandler.setWrapper);
  },

  setWrapper: function() {
    // width stuff from ppk's http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/index.html
    var theHeight = 0;
    if (window.innerHeight) {
	theHeight = window.innerHeight
    } else if (document.documentElement &&
                document.documentElement.clientHeight) {
	theHeight = document.documentElement.clientHeight
    } else if (document.body) {
	theHeight = document.body.clientHeight
    }
    if (theHeight != 0 && document.getElementById('wrapper') != null) {
      if (theHeight < 400) {
        document.getElementById('wrapper').className = 'page layout-default';
      } else if (theHeight < 700) { //600
        document.getElementById('wrapper').className = 'page layout-medium1';
      } else if (theHeight < 800) {
        document.getElementById('wrapper').className = 'page layout-medium2';
      } else {
        document.getElementById('wrapper').className = 'page layout-widest';
      }
    }
  },

  addEvent: function( obj, type, fn ) {
    if ( obj.attachEvent ) {
      obj['e'+type+fn] = fn;
      obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
      obj.attachEvent( 'on'+type, obj[type+fn] );
    } else {
      obj.addEventListener( type, fn, false );
    }
  }
}

//wraphandler.addEvent(window,"load",wraphandler.init);

//////////////////////////////////////////////////////////////////////
function Lebrand_GetPageSize()
{
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function ResizePageElementByID(Element)
{
  var arPageSize = Lebrand_GetPageSize();
  var PageHeight = arPageSize[1];
  
  PageHeight -= 65;
  
  if(PageHeight > 867) PageHeight = 867;
  
  $(Element).css("height", PageHeight+"px");
  $(Element+" .left").css("height", PageHeight+"px");
  if($(Element+" .left-top") && $(Element+" .left-top").length) $(Element+" .left-top").css("height", PageHeight+"px");
  $(Element+" .right").css("height", PageHeight+"px");
  
  $(".foo_bg").css("top", ($(Element).height() + 35 - 200) + "px");
  //$(".foo_bg em").css("top", (arPageSize[1] - 200) + "px");
}
