var wys = 150;

window.onerror=function(desc,page,line,chr){
/* alert('JavaScript error occurred! \n'
  +'\nError description: \t'+desc
  +'\nPage address:      \t'+page
  +'\nLine number:       \t'+line
 );*/
}
$(function(){
 $('a').focus(function(){this.blur();});
 SI.Files.stylizeAll();
 verticalSlider.init();

 $('input.text-default').each(function(){
  $(this).attr('default',$(this).val());
 }).focus(function(){
  if($(this).val()==$(this).attr('default'))
   $(this).val('');
 }).blur(function(){
  if($(this).val()=='')
   $(this).val($(this).attr('default'));
 });

 $('input.text,textarea.text').focus(function(){
  $(this).addClass('textfocus');
 }).blur(function(){
  $(this).removeClass('textfocus');
 });

 var popopenobj=0,popopenaobj=null;
 $('a.popup').click(function(){
  var pid=$(this).attr('rel').split('|')[0],_os=parseInt($(this).attr('rel').split('|')[1]);
  var pobj=$('#'+pid);
  if(!pobj.length)
   return false;
  if(typeof popopenobj=='object' && popopenobj.attr('id')!=pid){
   popopenobj.hide(50);
   $(popopenaobj).parent().removeClass(popopenobj.attr('id').split('-')[1]+'-open');
   popopenobj=null;
  }
  return false;
 });
 $('p.images img').click(function(){
  var newbg=$(this).attr('src').split('bg/bg')[1].split('-thumb')[0];
  $(document.body).css('backgroundImage','url('+_siteRoot+'images/bg/bg'+newbg+'.jpg)');
 
  $(this).parent().find('img').removeClass('on');
  $(this).addClass('on');
  return false;
 });
 $('div.sc-large div.img:has(div.tml)').each(function(){
  $('div.tml',this).hide();
  $(this).append('<a href="#" class="tml_open">&nbsp;</a>').find('a').css({
   left:parseInt($(this).offset().left),top:parseInt($(this).offset().top)+1
  }).click(function(){
   $(this).siblings('div.tml').slideToggle();
   return false;
  }).focus(function(){this.blur();}); 
 });
});
var verticalSlider = {
    num: 0,
    cur: -1,
    cr: [],
    al: null,
    at: 50 * wys,
    ar: true,
    init: function() {
        if (!verticalSlider.data || !verticalSlider.data.length)
            return false;
        var verticalD = verticalSlider.data;
        verticalSlider.num = verticalD.length;
        var verticalPos = verticalSlider.num;
        verticalSlider.cur = verticalPos;
        verticalSlider.al = window.setTimeout('verticalSlider.auto();', verticalSlider.at);
    },
    auto: function() {
        if (!verticalSlider.ar)
            return false;

        var next = verticalSlider.cur + 1;
        if (next >= verticalSlider.num) {
            verticalSlider.slideAuto(0);
        }
        else {
            verticalSlider.slideAuto(next);
        }
    },
    slideAuto: function(verticalPos) {
        window.clearTimeout(verticalSlider.al);
        verticalSlider.al = window.setTimeout('verticalSlider.auto();', verticalSlider.at);
        var verticalD = verticalSlider.data;



        if (verticalPos == 0) {
            for (var i = 1; i < verticalSlider.num; i++) {
                document.getElementById(verticalD[i].id).style.top = '-'+wys + 'px';
            }
            $('#' + verticalD[verticalSlider.num - 1].id).stop().animate({ top: -wys }, wys, 'swing');
            document.getElementById(verticalD[0].id).style.top = wys + 'px';
            $('#' + verticalD[0].id).stop().animate({ top: 0 }, wys, 'swing');
        }
        else {
            document.getElementById(verticalD[verticalPos - 1].id).style.top = '0px';
            $('#' + verticalD[verticalPos - 1].id).stop().animate({ top: (-wys) }, wys, 'swing');
            document.getElementById(verticalD[verticalPos].id).style.top = wys + 'px';
            $('#' + verticalD[verticalPos].id).stop().animate({ top: 0 }, wys, 'swing');
        }
        verticalSlider.cur = verticalPos;
    },
    slide: function(verticalPos) {
        if (verticalPos == verticalSlider.cur)
            return;
        if (verticalSlider.cur > verticalPos) {
            for (var i = verticalPos + 1; i < verticalSlider.num; i++) {
                verticalSlider.slideAuto(i);
            }
        }
        for (var i = 0; i < verticalPos; i++) {
            verticalSlider.slideAuto(i);
        }
        verticalSlider.slideAuto(verticalPos);

    }
};
// STYLING FILE INPUTS 1.0 | Shaun Inman <http://www.shauninman.com/> | 2007-09-07
if(!window.SI){var SI={};};
SI.Files={
 htmlClass:'SI-FILES-STYLIZED',
 fileClass:'file',
 wrapClass:'cabinet',
 
 fini:false,
 able:false,
 init:function(){
  this.fini=true;
 },
 stylize:function(elem){
  if(!this.fini){this.init();};
  if(!this.able){return;};
  
  elem.parentNode.file=elem;
  elem.parentNode.onmousemove=function(e){
   if(typeof e=='undefined') e=window.event;
   if(typeof e.pageY=='undefined' &&  typeof e.clientX=='number' && document.documentElement){
    e.pageX=e.clientX+document.documentElement.scrollLeft;
    e.pageY=e.clientY+document.documentElement.scrollTop;
   };
   var ox=oy=0;
   var elem=this;
   if(elem.offsetParent){
    ox=elem.offsetLeft;
    oy=elem.offsetTop;
    while(elem=elem.offsetParent){
     ox+=elem.offsetLeft;
     oy+=elem.offsetTop;
    };
   };
  };
 },
 stylizeAll:function(){
  if(!this.fini){this.init();};
  if(!this.able){return;};
 }
};
