function el(id) { return document.getElementById(id); }

function BrowserDetect() {
 var ua = navigator.userAgent.toLowerCase();
 // browser engine name
 this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
 this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);
 // browser name
 this.isKonqueror   = (ua.indexOf('konqueror') != -1);
 this.isSafari      = (ua.indexOf('safari') != - 1);
 this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
 this.isOpera       = (ua.indexOf('opera') != -1);
 this.isIcab        = (ua.indexOf('icab') != -1);
 this.isAol         = (ua.indexOf('aol') != -1);
 this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );
 this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
 this.isFirefox     = (ua.indexOf('firefox/') != -1 || ua.indexOf('firebird/') != -1);
 this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
 // spoofing and compatible browsers
 this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
 this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
 // rendering engine versions
 this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
 this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
 this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
 // browser version
 this.versionMinor = parseFloat(navigator.appVersion);
 // correct version number
 if (this.isGecko && !this.isMozilla) {
  this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
 } else if (this.isMozilla) {
  this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
 } else if (this.isIE && this.versionMinor >= 4) {
  this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
 } else if (this.isKonqueror) {
  this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
 } else if (this.isSafari) {
  this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
 } else if (this.isOmniweb) {
  this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
 } else if (this.isOpera) {
  this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
 } else if (this.isIcab) {
  this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
 }
 this.versionMajor = parseInt(this.versionMinor);
 // dom support
 this.isDOM1 = (document.getElementById);
 this.isDOM2Event = (document.addEventListener && document.removeEventListener);
 // css compatibility mode
 this.mode = document.compatMode ? document.compatMode : 'BackCompat';
 // platform
 this.isWin    = (ua.indexOf('win') != -1);
 this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
 this.isMac    = (ua.indexOf('mac') != -1);
 this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
 this.isLinux  = (ua.indexOf('linux') != -1);
 // specific browser shortcuts
 this.isNS4x = (this.isNS && this.versionMajor == 4);
 this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
 this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
 this.isNS4up = (this.isNS && this.versionMinor >= 4);
 this.isNS6x = (this.isNS && this.versionMajor == 6);
 this.isNS6up = (this.isNS && this.versionMajor >= 6);
 this.isNS7x = (this.isNS && this.versionMajor == 7);
 this.isNS7up = (this.isNS && this.versionMajor >= 7);
 this.isIE4x = (this.isIE && this.versionMajor == 4);
 this.isIE4up = (this.isIE && this.versionMajor >= 4);
 this.isIE5x = (this.isIE && this.versionMajor == 5);
 this.isIE55 = (this.isIE && this.versionMinor == 5.5);
 this.isIE5up = (this.isIE && this.versionMajor >= 5);
 this.isIE6x = (this.isIE && this.versionMajor == 6);
 this.isIE6up = (this.isIE && this.versionMajor >= 6);
 this.isIE4xMac = (this.isIE4x && this.isMac);
}

var browser=new BrowserDetect();

function explode(delimiter,string){var emptyArray={0:''};if(arguments.length!=2||typeof arguments[0]=='undefined'||typeof arguments[1]=='undefined'){return null}if(delimiter===''||delimiter===false||delimiter===null){return false}if(typeof delimiter=='function'||typeof delimiter=='object'||typeof string=='function'||typeof string=='object'){return emptyArray}if(delimiter===true){delimiter='1'}return string.toString().split(delimiter.toString())}
function implode(glue,pieces){return((pieces instanceof Array)?pieces.join(glue):pieces)}
function in_array(needle,haystack,strict){var found=false,key,strict=!!strict;for(key in haystack){if((strict&&haystack[key]===needle)||(!strict&&haystack[key]==needle)){found=true;break}}return found}
function array_search(needle,haystack,strict){var strict=!!strict;for(var key in haystack){if((strict&&haystack[key]===needle)||(!strict&&haystack[key]==needle)){return key}}return false}

function sm_to(str){str=hex_to_str(str);location.href='mailto:'+str}

function dec_to_hex(d){return d.toString(16)}
function hex_to_dec(h){return parseInt(h,16)}
function hex_to_str(str){var i=0;var res='';for(i=0;i<(Math.floor(str.length/2));i++)res=res+''+String.fromCharCode(hex_to_dec(str.substr(i*2,2)));return res}

function focus_input(nam){hnd=el(nam);if(hnd.value==hnd.title)hnd.value=''}
function blur_input(nam){hnd=el(nam);if(hnd.value=='')hnd.value=hnd.title}

var zoom_on=true;

function ajx_zoomer(image_s,size_w,size_h,size_tune) {
	el('ajx_zoomer').innerHTML='';
	JsHttpRequest.query(
		document.getElementsByTagName('base')[0].href+'ajax.php?&ajx=zoom',
		{'ajx_src':image_s,'ajx_w':size_w,'ajx_h':size_h,'ajx_t':size_tune},
		function(result,errors) {
			if (result) {
				el('ajx_zoomer').innerHTML=result["ajx_zoom"];
				if (size_tune) {
					var w=result["ajx_w"];
					var h=result["ajx_h"];
					var fader_pos_x=$(window).scrollLeft();
					var fader_pos_y=$(window).scrollTop();
					var window_w=$(window).width();
					var window_h=$(window).height();
					var zoomer_pos_x=Math.floor((window_w-w)/2+fader_pos_x);
					var zoomer_pos_y=Math.floor((window_h-h)/2+fader_pos_y);
					$("#zoomer").animate({top:zoomer_pos_y,left:zoomer_pos_x,width:w,height:h},400,function(){
						$("#ajx_zoomer").show();
					});
				}
				return false;
			}
		},
		true
	);
}

function popUpWin(url,win,w,h){var leftPos=(screen.availWidth-w)/2;var topPos=(screen.availHeight-h)/2;opt='width='+w+',height='+h+',left='+leftPos+',top='+topPos+',toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';window.open(url,win,opt)}
function popUpWinS(url,win,w,h){var leftPos=(screen.availWidth-w)/2;var topPos=(screen.availHeight-h)/2;opt='width='+w+',height='+h+',left='+leftPos+',top='+topPos+',toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1';window.open(url,win,opt)}

var is_not_dsm=true;
$(document).ready(function(){
$(window).bind('scroll',function(){
$("#fader").css({top:0,left:0,width:1,height:1}); $("#zoomer").css({top:0,left:0,width:1,height:1}); $("#fader").hide(); $("#zoomer").hide(); $("#ajx_zoomer").hide();
is_not_dsm=true;
});
$(window).bind('resize',function(){
$("#fader").css({top:0,left:0,width:1,height:1}); $("#zoomer").css({top:0,left:0,width:1,height:1}); $("#fader").hide(); $("#zoomer").hide(); $("#ajx_zoomer").hide();
is_not_dsm=true;
});
$("#zoomer,#fader,#ajx-zoomer").click(function(){
if(is_not_dsm){
	$("#fader").css({top:0,left:0,width:1,height:1}); $("#zoomer").css({top:0,left:0,width:1,height:1}); $("#fader").hide(); $("#zoomer").hide(); $("#ajx_zoomer").hide();
	is_not_dsm=true;
}
});
$("IMG.zoom").click(function(){
if (!zoom_on) return false;
var image_s=$(this).attr("SRC");
var image_w=0; var image_h=0;
var ttl=$(this).attr("TITLE");
if (ttl==undefined) ttl='';
var lst=ttl.lastIndexOf(' (')
if (lst>=0) {
var ttl=ttl.substr(lst+2);
var sep1=ttl.indexOf('x');
var sep2=ttl.indexOf(')');
if ((sep1>=0)&&(sep2>=0)) {
image_w=parseInt(ttl.substring(0,sep1));
image_h=parseInt(ttl.substring(sep1+1,sep2));
}}
if ((image_w>0)&&(image_h>0)) {
//siz
var pos=$(this).offset();
var w=$(this).width();
var h=$(this).height();
var window_w=$(window).width();
var window_h=$(window).height();
/*
if ((image_w<window_w)&&(image_h<window_h)) {
size_w=image_w; size_h=image_h;
} else {
var size_list=new Array(300,500,700);
for (v in size_list) {
if (image_w>image_h) {
tmp_w=size_list[v];	tmp_h=image_h/image_w*tmp_w;
if ((tmp_w<=window_w)&&(tmp_h<=window_h)&&(tmp_w<=image_w)&&(tmp_h<=image_h)) { size_w=Math.floor(tmp_w); size_h=Math.floor(tmp_h); }
} else {
tmp_h=size_list[v];	tmp_w=image_w/image_h*tmp_h;
if ((tmp_w<=window_w)&&(tmp_h<=window_h)&&(tmp_w<=image_w)&&(tmp_h<=image_h)) { size_w=Math.floor(tmp_w); size_h=Math.floor(tmp_h); }
}}}
*/
var size_list=new Array(300,500,700);
for (v in size_list) {
tmp_w=size_list[v];	tmp_h=Math.floor(image_h/image_w*tmp_w);
if (tmp_w<=(window_w-200)) {
if (tmp_h>(window_h-100)) tmp_h=window_h-100;
if ((tmp_w<=image_w)&&(tmp_h<=image_h)) { size_w=Math.floor(tmp_w); size_h=Math.floor(tmp_h); }
}
}
//ajx
ajx_zoomer(image_s,size_w,size_h,false);
//pos
var fader_pos_x=$(window).scrollLeft();
var fader_pos_y=$(window).scrollTop();
var zoomer_pos_x=Math.floor((window_w-size_w)/2+fader_pos_x);
var zoomer_pos_y=Math.floor((window_h-size_h)/2+fader_pos_y);
//ani
$("#fader").css({top:fader_pos_y,left:fader_pos_x,width:window_w,height:window_h,opacity:0.0});
$("#fader").show();
$("#zoomer").css({top:pos.top,left:pos.left,width:w,height:h,opacity:0.0});
$("#zoomer").show();
$("#fader").animate({opacity:0.7},400);
$("#zoomer").animate({top:zoomer_pos_y,left:zoomer_pos_x,width:size_w,height:size_h,opacity:1.0},400,function(){
$("#ajx_zoomer").show();
});
} else {
//siz
var pos=$(this).offset();
var w=$(this).width();
var h=$(this).height();
var window_w=$(window).width();
var window_h=$(window).height();
size_w=0; size_h=0;
//ajx
ajx_zoomer(image_s,window_w,window_h,true);
//pos
var fader_pos_x=$(window).scrollLeft();
var fader_pos_y=$(window).scrollTop();
var zoomer_pos_x=Math.floor((window_w-w)/2+fader_pos_x);
var zoomer_pos_y=Math.floor((window_h-h)/2+fader_pos_y);
//ani
$("#fader").css({top:fader_pos_y,left:fader_pos_x,width:window_w,height:window_h,opacity:0.0});
$("#fader").show();
$("#zoomer").css({top:pos.top,left:pos.left,width:w,height:h,opacity:1.0});
$("#zoomer").show();
$("#fader").animate({opacity:0.7},400);
}
return false;
});
});

