
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 initSliderData() {
    slider.data = new Array();
    $('#slide-runner > a img').each(function() {
        var text = $(this).attr('alt').split(':');
        slider.data.push({
            'id': this.id,
            'client': text[0],
            'desc': text[1]
        });
    });

};

$(function(){
 $('a').focus(function(){this.blur();});

    $('div#corner').click(function() {
        document.location.href = $(this).parent().find('a img').filter(function() { return $(this).css('left') === '0px'; }).parent().attr('href');
    }); 
    
 initSliderData();
 slider.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;
 });


});

var slider = {
    num: -1,
    cur: 0,
    cr: [],
    al: null,
    at: 10 * 1000,
    ar: true,
    init: function() {
        if (!slider.data || !slider.data.length)
            return false;

        var d = slider.data;
        slider.num = d.length;
        var pos = Math.floor(Math.random() * 1);
        if (showSlideshowNavigation) {
            for (var i = 0; i < slider.num; i++) {
                $('#' + d[i].id).css({ left: ((i - pos) * 1000) });
                $('#slide-nav').append('<a id="slide-link-' + i + '" href="#" onclick="slider.slide(' + i + ');return false;" onfocus="this.blur();">' + (i + 1) + '</a>');
            }
        }
        $('img,div#slide-controls', $('div#slide-holder')).fadeIn();
        slider.text(d[pos]);
        slider.on(pos);
        slider.cur = pos;
        window.setTimeout('slider.auto();', slider.at);
    },
    auto: function() {
        if (!slider.ar)
            return false;

        var next = slider.cur + 1;
        if (next >= slider.num) next = 0;
        slider.slide(next);
    },
    slide: function(pos) {
        if (pos < 0 || pos >= slider.num || pos == slider.cur)
            return;

        window.clearTimeout(slider.al);
        slider.al = window.setTimeout('slider.auto();', slider.at);

        var d = slider.data;
        for (var i = 0; i < slider.num; i++)
            $('#' + d[i].id).stop().animate({ left: ((i - pos) * 1000) }, 1000, 'swing');

        slider.on(pos);
        slider.text(d[pos]);
        slider.cur = pos;
    },
    on: function(pos) {
        $('#slide-nav a').removeClass('on');
        $('#slide-nav a#slide-link-' + pos).addClass('on');
    },
    text: function(di) {
        slider.cr['a'] = di.client;
        slider.cr['b'] = di.desc;
        slider.ticker('#slide-client span', di.client, 0, 'a');
        slider.ticker('#slide-desc', di.desc, 0, 'b');
    },
    ticker: function(el, text, pos, unique) {
        if (slider.cr[unique] != text)
            return false;

        ctext = text.substring(0, pos) + (pos % 2 ? '-' : '_');
        $(el).html(ctext);

        if (pos == text.length)
            $(el).html(text);
        else
            window.setTimeout('slider.ticker("' + el + '","' + text + '",' + (pos + 1) + ',"' + unique + '");', 30);
    }
};
