/* 
	(c) 2007, Mediaweb Studio 
*/


function get_browser()
{
var bver=null;
if(document.layers)
{bver='nn4';
}
else if(document.all)
{
if(window.opera)
  {bver='opera';
  }
else
  {bver='ie4';
  }
}
else if(document.getElementById)
{
if(navigator.userAgent.indexOf('gecko')>-1)
  {bver='mozilla';
  }
else
  {bver='nn6';
  }
}
if((window.opera)&&((navigator.appVersion.indexOf('MSIE 5.0')>-1)||(parseInt(navigator.appVersion)==6)))
{
bver='opera6';
}
return bver;
}


function replace_tags(STR,STR1,STR2)
{
var rexp,S;
S=STR;
rexp=new RegExp(STR1,"gi");
S=S.replace(rexp,STR2);
return S;
}


function preloadImg(file) {
  img = new Image();
  img.src = file;
}


function change_image(elname, srcname) {
if (srcname=='1') {
  elname.src=replace_tags(elname.src,'\.gif','_over.gif');
}
else {
  elname.src=replace_tags(elname.src,'_over.gif','\.gif');
}
}


function change_image(elname, srcname) {
if (srcname=='1') {
  elname.src=replace_tags(elname.src,'\.gif','_over.gif');
}
else {
  elname.src=replace_tags(elname.src,'_over.gif','\.gif');
}
}

function NewWindow(w,v,s,d)
{
var w_top=screen.height/2;
var w_left=screen.width/2;
if(s>0)
{
w_top=w_top-s/2;
}
if(d>0)
{
w_left=w_left-d/2;
}
eval("window.open('"+v+"','"+w+"','height="+s+",width="+d+",top="+w_top+",left="+w_left+"status=no,location=no,toolbar=no,directories=no,menubar=no,scrollbars=0');");
} 



function CookieHandler(){
	this.setCookie = function (name, value, seconds){
		if (typeof(seconds) != 'undefined') {
			var date = new Date();
			date.setTime(date.getTime() + (seconds*1000));
			var expires = "; expires=" + date.toGMTString();
		}else{
			var expires = "";
		}
		document.cookie = name+"="+value+expires+"; path=/";
	}
	this.getCookie = function(name){
		name = name + "=";
		var carray = document.cookie.split(';');
		for(var i=0;i < carray.length;i++){
			var c = carray[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
		}
		return null;
	}
	this.deleteCookie = function (name){
		this.setCookie(name, "", -1);
	}
}





$.fn.valueOnfocus = function(){
  function formCheeck(form,field,val){
    $(form).bind('submit',function(){
      if($(field).val()==val){
        $(field).val('');
      }
      return true;
    });
  }
  function findForm(elem){
    var form = $(elem).parent();
    if($(form).is('form')==false){
      return findForm(form);
    }else{
      return form;
    }
  }
  $(this).each(function(i){
    var value = $(this).attr('title');
    if($(this).is(':password')){
      var passInput = $(this);
      var inputStyle = $(this).attr('style') ? $(this).attr('style') : '';
      $(passInput).after('<input type="text" class="'+$(passInput).attr('class')+'" value="'+value+'" title="'+$(passInput).attr('title')+'" style="'+inputStyle+'">');
      var textInput = $(this).next();
      if($(passInput).val()==''){
        $(passInput).val("").hide();
      }else{
        $(textInput).hide();
      }
      $(textInput).focus(function(){
        if($(this).val()==value || $(this).val()==''){
          $(passInput).show().focus();
          $(this).hide();
        }
      });
      $(passInput).blur(function(){
        if($(this).val()==""){
          $(this).hide();
          $(textInput).show();
        }
      });
    }else{
      if($(this).val()=='')
        $(this).val(value);
      $(this)
      .focus(function(){
        if($(this).val()==value || $(this).val()==''){
          $(this).val("");
        }
      })
      .blur(function(){
        if($(this).val()=="")
          $(this).val(value);
      });
    }
    var thisForm = findForm($(this));
    formCheeck(thisForm,$(this),value);
  });
  return this;
}


$.fn.jsSelect = function(){
  var parent = $(this);
  var list = $('ul:first',parent);
  var value = $('span:first',parent);
  $(this).click(function(){
    if($(list).css('display')!='block')
      $(list).show();
    else
      $(list).hide();
  });
  $(list).mouseleave(function(){
    $(this).hide();
  });
  $('li',list).each(function(i){
    $(this)
    .click(function(){
      var selectedVal = $(this).text();
      $(value).text(selectedVal);
      var patt = /\d*/;
      var id = patt.exec($(this).attr('class').replace('id',''));
      var Cookies = new CookieHandler();
      Cookies.setCookie('cur_region', id, 3600);
      if(document.location.search.substr(1)==''){
        window.location.reload();
      }else{
        window.location.href = window.location.pathname;
      }
    })
    .hover(function(){
      $(this).toggleClass('hover');
    },function(){
      $(this).toggleClass('hover');
    });
  });
};



$(document).ready(function(){
  $('#thatLink')
  .click(function(){
    $.fn.colorbox({'open':true, 'width':'400px','initialWidth': 100,'initialHeight': 100,'href':$(this).attr('href'), 'opacity': 0.2});
    //$('#colorbox').css({});
    return false;
  });
});

