function initPage(){
	initInputs();
	initTabs();
}
function initInputs() {
	var _inputs = document.getElementsByTagName('input');
	if (_inputs) {
		for(var i=0; i<_inputs.length; i++) {
			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
				_inputs[i].alt = _inputs[i].value;

				_inputs[i].onfocus = function(){
					if(this.value==this.alt) this.value='';
					_value = this.value;
				}
				_inputs[i].onblur = function(){
					if (this.value == '')
					this.value = this.alt;
				}
			}
		}
	}
}
function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1)
		{
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));
					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";
					links[j].onclick = function ()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							for (var i = 0; i < this.tabs.length; i++)
							{
								document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.display = "none";
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							Cufon.refresh('.promo .tabset a');
							return false;
						}
					}
				}
			}
		}
	}
}
if (window.addEventListener) window.addEventListener("load", initPage, false);
else if (window.attachEvent) window.attachEvent("onload", initPage);


var isMSIE=/*@cc_on!@*/false; // http://dean.edwards.name/weblog/2007/03/sniff/
var isIEmac=false; /*@cc_on @if(@_jscript&&!(@_win32||@_win16)&& 
(@_jscript_version<5.5)) isIEmac=true; @end @*/
var undefined;

function isEmpty(s){return ((s=='')||/^\s*$/.test(s));}

var addBookmarkObj = {
  linkText:'Bookmark This Page',
  title:document.title,
  URL:location.href,
  addTextLink:function(parId){
    if(addBookmarkObj.checkMobileDevice()) return;
    var a=addBookmarkObj.makeLink(parId,1);
    if(a){
      jQuery(a).text(addBookmarkObj.linkText);
      return;
    }
    var cont=addBookmarkObj.getParent(parId);
    if(!cont) return;
    jQuery(cont).append('<span>'+addBookmarkObj.findKeys()+'</span>');
  },
  addImageLink:function(parId,imgPath){
    if(!imgPath || isEmpty(imgPath)) return;
    if(addBookmarkObj.checkMobileDevice()) return;
    var o=addBookmarkObj,a=o.makeLink(parId),img=document.createElement('img');
    img.title=img.alt=o.modal?o.linkText:o.findKeys();
    img.src=imgPath;
    a.appendChild(img);
  },
  makeLink:function(parId,isText){
    var cont=addBookmarkObj.getParent(parId);
    if(!cont) return null;
    var a=document.createElement('a');
    a.href=addBookmarkObj.URL;
    var s=document.createElement('div').style;
    var isFx35plus=((navigator.userAgent.toLowerCase().indexOf('firefox')!=-1)
      && (s.wordWrap!==undefined) && (s.MozTransform!==undefined));
    if(window.external && isMSIE && !isIEmac){
      // IE4/Win generates an error when you
      // execute 'typeof(window.external.AddFavorite)'
      // In IE7 the page must be from a web server, not directly from a local 
      // file system, otherwise, you will get a permission denied error.
      // Maxthon shows 'typeof(window.external.AddFavorite)' as 'undefined'
      // even though it is defined.
      a.onclick=function(){ // IE/Win
        try {
          window.external.AddFavorite(addBookmarkObj.URL,addBookmarkObj.title);
        } catch(ex){
          addBookmarkObj.displayMsg(addBookmarkObj.findKeys());
        }
        return false;
      }
      addBookmarkObj.modal=1;
    } else if(window.opera || isFx35plus){ // Opera 7+, Firefox 3.5+
      a.title=addBookmarkObj.title,a.rel='sidebar';
      addBookmarkObj.modal=1;
    } else if(isText) {
      return null;
    } else {
      a.onclick=function(){
        addBookmarkObj.displayMsg(this.firstChild.title);
        return false;
      }
    }
    return cont.appendChild(a);
  },
  displayMsg:function(t){
  	alert('After closing this dialog, '+t.charAt(0).toLowerCase()+t.slice(1));
  },
  getParent:function(parId){
    if(!document.getElementById || !document.createTextNode) return null;
    parId=((typeof(parId)=='string')&&!isEmpty(parId))
      ?parId:'addBookmarkContainer';
    return document.getElementById(parId)||null;
  },
  findKeys:function(){
    // user agent sniffing is bad in general, but this is one of the times 
    // when it's really necessary
    var ua=navigator.userAgent.toLowerCase(),Webkit=(ua.indexOf('webkit')!=-1),
      Mac=/mac(\s*os|intosh|.*p(ower)?pc)/.test(ua),
      str=(Mac?'Command/Cmd':'CTRL');
    if(window.opera && (!opera.version || (opera.version()<9))) {
      str+=' + T';  // Opera versions before 9
    } else if(ua.indexOf('konqueror')!=-1) {
      str+=' + B'; // Konqueror
    } else if(window.opera || window.home || Webkit || isMSIE || Mac) {
      // IE, Firefox, Netscape, Safari, Google Chrome, Opera 9+, iCab, IE5/Mac
      str+=' + D';
    }
    return ((str)?'Press '+str+' to bookmark this page.':str);
  },
  checkMobileDevice:function(){
    var r='iphone|ipod|android|palm|symbian|windows ce|windows phone|iemobile|'+
    'blackberry|smartphone|netfront|opera m|htc[-_].*opera';
    return (new RegExp(r)).test(navigator.userAgent.toLowerCase());
  }
}


$(document).ready(function() {
    $('#addfavorite').each(function() {
	addBookmarkObj.addImageLink('addfavorite','/graphics/icon-like.gif');
    });
    setInterval(function() {
	if($('.highslide-wrapper').length > 0) {
	    $('iframe, object, embed').addClass('highslide-hidden').css('visibility','hidden');
        }
	else {
	    $('.highslide-hidden').css('visibility','visible').removeClass('highslide-hidden');
        }
    }, 500);
});

hs.graphicsDir = '/js/highslide/highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.numberPosition = 'caption';
hs.dimmingOpacity = 0.9;
hs.fadeInOut = true;
hs.showCredits = false;
hs.addSlideshow({
    interval: 5000,
    repeat: true,
    useControls: true,
    fixedControls: 'fit',
    overlayOptions: {
	opacity: 0.75,
	position: 'bottom center',
	hideOnMouseOut: true
    }
});

