var currentLink = document.URL;


$(document).ready(
	function(){
		zipAddEvents();
	}
);

function zipAddEvents(){  
	
	$('#newFeedback').show();
	
	if ($('#newMsg').length) {
		InfoBox.open('/rq/new_msg.php',{width: 460, height:310});
		$('#infobox3_content_table2 tr:first, #infobox3_content_table2 tr:last').hide();
		$('#infobox3_l, #infobox3_r').hide();
		$('#infobox3_box_content').css('background-color','transparent');
		$('#infobox3_box').css('background-color','transparent');
		$('#infobox3_overlay').click(function(){InfoBox.close();});
	}
	
	$('.loginButton').click(function(){
		var info_title = new String($(this).attr('rel'));
		InfoBox.iframe('/layout/login.php',{title : info_title, width: 350, height: 250});
		return false;
	});
	$('.registerButton').click(function(){
		var info_title = new String($(this).attr('rel'));
		InfoBox.iframe('/layout/register.php',{title : info_title, width: 732, height: 350});
		return false;
	});
	// Ad Image overlay
		
		if ($("#thumb_view .ad_box1").length > 0) {
			$("#thumb_view .ad_box1 a").hover(
				function(){
					$("a[adid="+$(this).attr("adid")+"] .over").fadeIn('fast');
				},
				function(){
					$("a[adid="+$(this).attr("adid")+"] .over").fadeOut('fast');
				}
			);
		}

	$('a.show').click(adShow);
	$('#popup_ct a.zip_child, #view_menu a.zip_child, #popup_ct a.dr').click(
		function(){
			var path = false;
			try{
				path = window.opener.location.pathname;
			} catch(e){}

			if(path != '/export/kasjauns.php' && path != '/export/banner.php'){
				window.opener.location = this.href;
				window.opener.focus();
				return false;
			} else {
				window.opener.top.location = this.href;
				window.opener.top.focus();
				return false;
			}
		}
	);
	$('#ad_view a.zip_ajax, #ad_view .navigation a').click(
		function(){
			currentLink = this.href;
			if(true ||  this.href.indexOf('view')>-1){
				url = this.href.split('#')[0];
				divider = url.indexOf('?')>-1?'&':'?';
				$('#ad_view').load( url + divider,null,zipAddEvents);
			}
			if(this.href.indexOf('#zip_center')>-1){
				window.location.href='#zip_center';
			}
			return false;
		}
	);
	// +++++++++++++++++++++++++ FAVORITE ICON +++++++++++++++++++++++++++++++++++	
  var fav_icon_on = '/img/star_on.png';
  var fav_icon_off = '/img/star_off.png';
  function fav_icon_onclick( e ){
    if( typeof( e ) != 'undefined' && e.stopPropagation ) {    
      e.stopPropagation();
    } else if( window.event ) {    
      window.event.cancelBubble = true;
    } // if( event.stopPropagation ) {
    if( this.isfav ){
      //this.src = fav_icon_off;
      this.className = 'fav_icon fav_icon_off';
      this.title_ = fav_icon_title_on;
      $.get( '/show/?exit&fav=0&i=' + this.ad_id );
    } else {
      //this.src = fav_icon_on;
      this.className = 'fav_icon fav_icon_on';
      this.title_ = fav_icon_title_off
      $.get( '/show/?exit&fav=1&i=' + this.ad_id );
    }
    $('#tooltip h3').html(this.title_);    
    this.isfav = ! this.isfav;
    return false;
  }  
  $('#ad_view a.fav').each(
		function(){
      var ad_id = this.getAttribute('adid');		  
		  if( Number( this.getAttribute('isfav') ) ){
  		  this.fav_icon = DOM.make( {
          tag:'div',
          className:'fav_icon fav_icon_on',
          prop:{
            ad_id:ad_id,
            isfav:true,
            src:fav_icon_on,
            onclick:fav_icon_onclick,
            title_:fav_icon_title_off,
            title:' '
          }
        } ).Append( this );
        $(this.fav_icon).tooltip({delay: 0,track: true, showURL: false});
      }
			this.onmouseover=function(){			  
				if( ! this.fav_icon ){
          this.fav_icon = DOM.make( {
            tag:'div',
            className:'fav_icon fav_icon_off',
            prop:{
              ad_id:ad_id,
              isfav:false,              
              src:fav_icon_off,
              onclick:fav_icon_onclick,              
              title_:fav_icon_title_on,
              title:' '              
            }
          } ).Append( this );          
         $(this.fav_icon).tooltip({delay: 0,track: true, showURL: false});
        } else{
          this.fav_icon.style.visibility = '';
        }
        $('#tooltip h3').html(this.fav_icon.title_);                
			}; // // this.onmouseover=function(){
			this.onmouseout=function(){
        if( this.fav_icon && ! this.fav_icon.isfav ) this.fav_icon.style.visibility = 'hidden';			 
			};
		}
	);
	// ------------------------- FAVORITE ICON -----------------------------------
	$('#choose_category a.zip_create').click(
		function(){
			url = this.href.split('#')[0];
			divider = url.indexOf('?')>-1?'&':'?';
			$('#zip_center').load( url + divider,null,zipAddEvents);
			return false;
		}
	);
	$('#ad_view_admin a.zip_delete').click(
			function(){
				if(confirm(confirmDeleteMsg)){
					return true;
				}
				return false;
		}
	);

	$('#currency_select').each(
		function(){
			this.onchange=function(){
				url = document.URL.split('#')[0];
				divider = url.indexOf('?')>-1?'&':'?';
				currency = this.options[this.selectedIndex].value;
				if(currentLink.indexOf('search')>-1){
					$('#ad_view').load( url + divider+'currency='+currency,null,zipAddEvents);
				} else {
					window.location = url + divider+'currency=' + currency;
				}
				return false;
			}
		}
	);	
	$('#navi_list li a').click(navi_list);

	if ($("#payment_status.autosubmit").length == 1 && $("#payment_status.autosubmit").attr('rel')) {
		window.location = $("#payment_status.autosubmit").attr('rel');
	}
	//console.info("ZIP Events loaded");
}




function navi_list(){
	child = $(this).parent('li').children('ul');
	if(child.size()){
		$('#navi_list ul ul').not($(this).parents()).slideUp(500);
		if(child.css('display')=='none'){
			child.slideDown(500);
		} else {
			child.slideUp(500);
		}	
		return false;
	}
}


function adShow(){
	url = this.href + '&popup=1';
	place = this.getAttribute('rel');
	if(typeof(search) != 'undefined' && place){
		url +='&search='+search+'&place='+place;
	}
	return adPopup(url);
}
	
function adPopup(url){
	var w=750;
	var h=620;
	var left = (screen.width) ? (screen.width-w)/2 : 0;
	var top = (screen.height) ? (screen.height-h)/2 : 0;
	var handle;
		
	if(handle=window.open(url,'ad_view'+(new Date().getTime()) ,'width='+w+', height='+h+', left='+left+', top='+top+', scrollbars=yes')){
		handle.focus();
	}
		return false;
}




function showImg(id){
	var obj;	
	if(obj = $('#adimg_'+id).get(0)){
	 var rightlink = '&nbsp;';
	 var leftlink = '&nbsp;';
	
	 InfoLite.open({text:'<img id="img_preview" alt="" src="/img/load.gif" onclick="showImg('+(id+1)+')" />', width:32, height:32});
		var pre = new Image();
		pre.onload = function(){

			if(id>0){
				leftlink = '<a id="previmg"	onclick="showImg('+(id-1)+'); return false;" href="#"><img src="http://ifrype.com/i/px.gif" alt="" /></a>';
			} else {
				leftlink = '';
			}
			if($('#adimg_'+(id+1)).size()){
				rightlink = '<a id="nextimg" onclick="showImg('+(id+1)+'); return false;" href="#"><img src="http://ifrype.com/i/px.gif" alt="" /></a>';
			}
			
			InfoLite.open({text:'<table width="100%" height="100%"><tr><td align="center"><div id="img_holder">'+leftlink+'<img id="img_preview" alt="" src="" onclick ="InfoLite.close();return false;" />'+rightlink+'</div></td></tr></table>', width:pre.width, height:pre.height+15});
			$('#img_preview').attr('src','');
			$('#img_preview').attr('src',obj.href);
			if($('#adimg_'+(id+1)).size()){
				var pre2 = new Image();

				pre2.src = $('#adimg_'+(id+1)).get(0).href;
			}
			$('#previmg, #nextimg').css('height',pre.height+'px');
			
		}
		pre.src = obj.href;
		
	} else {
		try {
			InfoLite.close();
		}
		catch(e) {}
	}
}

function listShowHide(list,textbox){
	if($(list).val()=='0' || list.options.length<=2){
		$('#'+textbox).show();
		$('#'+textbox+'inspShadow').show();
		//$('#'+textbox+'inspShadow').removeClass('hide');
		//$('#'+textbox).removeClass('hide');
	} else {
		$('#'+textbox).hide();
		$('#'+textbox+'inspShadow').hide();
		//$('#'+textbox+'inspShadow').addClass('hide');
		//$('#'+textbox).addClass('hide');
		$('#'+textbox).val('');
	}
}

function loadList(select, title, listname, listid, other, hide_if_empty, show_if_empty, cat, type){
	if(listid!=null){
		listname+='&p='+listid;
		if(cat!=null){
			listname+='&c='+cat;
			if(type!=null){
				listname+='&t='+type;	
			}	
		}
	}
	
	select = $('#'+select).get(0);
	var old = select.options[0].value;
	if(old==''){
		oldtext = select.options[0].text;
	}
	
	$.getJSON('/rq/list.php?l='+listname+(other?'&d':''),
        function(data){
        	for(i=select.options.length-1;i>=0;i--){
				select.remove(i);
			}
			if(old==''){
				select.options[select.options.length] = new Option(oldtext, '');
        	}
        	for (var i in data.list ){
				var s = new Option(data.list[i]['title'], i);
				if(data.list[i]['x'] && data.list[i]['y']){
					s.setAttribute('x',data.list[i]['x']);
					s.setAttribute('y',data.list[i]['y']);
				}
				if(data.list[i]['z']){
					s.setAttribute('z',data.list[i]['z']);
				}
				select.options[select.options.length] = s;
			} 
        	if(title){
        		$('#'+title).html(data['title']);
        	}
        	
 			if(hide_if_empty!=null){
				if(select.options.length>(other?2:1)){
					$(hide_if_empty).show();
					$(hide_if_empty+'inspShadow').show();
				} else {
					$(hide_if_empty).hide();
					$(hide_if_empty+'inspShadow').hide();
				}			
			}
			if(show_if_empty!=null){
				if(select.options.length>(other?2:1)){
					$(show_if_empty).hide();
					$(show_if_empty+'inspShadow').hide();
				} else {
					$(show_if_empty).show();
					$(show_if_empty+'inspShadow').show();
				}			
			}
        });
}

function izcel_paraugs( e, r, s ){
  var w = 470, h = 550;
  InfoLite.open({text:'<table><tr><td>'+
  '<div style="position:relative;"><img id="img_preview" alt="" src="'+e.href+'" />' +
  '<div class="paraugs_t1">'+ r + '</div>' +
  '<div class="paraugs_t2">'+ s + '</div>' +
  '</div></td></tr></table>', width:w, height:h+50});

  return false;
}

function noteikumi( e ){
  InfoBox.iframe( e.href, { title:(e.title ? e.getAttribute('title') : e.innerHTML), width:500, height:400, cache:false } );
  return false;
}

function paid_option(href, title){
	InfoBox.open(href+'&infoBox=1', { title:title, width:480, height:350, cache:false } );
	return false;
}


function block( e ){
  InfoBox.iframe( e.href, { title:(e.title ? e.getAttribute('title') : e.innerHTML), width:320, height:220, cache:false } );
  return false;
};

function link_iframe( e ){
  InfoBox.iframe( e.href, { title:(e.title ? e.getAttribute('title') : e.innerHTML), width:Number(e.getAttribute('iw')), height:Number(e.getAttribute('ih')), cache:false } );
  return false;
};

function sel_color_radio( e ){
  document.getElementById( 'ad_color_' + e.getAttribute( 'ad_color' ) ).checked = true;
}

function change_list_order( e ){
  var e2 = e.options[ e.selectedIndex ];
 $('#ad_view').load(e.getAttribute( 'url' ) + '?sort=' + e2.getAttribute( 'sort' ) + '&order=' + e2.getAttribute( 'order' ),null,zipAddEvents);
}

function fx_blink( e, par ){  
  par.count;  
  if( ! par.time ) par.time = 150; 
  if( e.timeout ) clearTimeout( e.timeout );
  if( par.count < 1 ) return false;  
  e.style.backgroundColor = '#EFF3F7';
  e.style.color = '#aaa';
  e.timeout = setTimeout( function(){
    e.style.backgroundColor = '';
    e.style.color = '';
    par.count --;
    e.timeout = setTimeout( function(){
      fx_blink( e, par );
    }, par.time ); 
  }, par.time );  
}



function map_position( select ){



  var e = select.options[ select.selectedIndex ];
 if( typeof( map ) != 'undefined' && Number( e.getAttribute( 'x' ) ) && Number( e.getAttribute( 'y' ) ) ){
    if( Number( e.getAttribute( 'z' ) ) ) map._.setCenter( new GLatLng( Number( e.getAttribute( 'y' ) ), Number( e.getAttribute( 'x' ) ) ) );
    if( Number( e.getAttribute( 'z' ) ) ) map._.setZoom( Number( e.getAttribute( 'z' ) ) );
  }
  showMap(document.getElementById('show_map_link'), true);  
}

function showMap(e, a){
  var div = document.getElementById( 'map_canvas_' );  
  if( Number( div.offsetHeight ) < 300 || ( typeof( a ) != 'undefined' && a ) ){
    div.style.height = 'auto';
    div.style.visibility = '';
    e.innerHTML = hide_map_text;
  } else {
    div.style.height = '1px';
    div.style.visibility = 'hidden';
    e.innerHTML = show_map_text;
  }
  return false;
}

function default_img(e){
  document.location.href+='&default=' + e.value;
}

var xZip = {};
function dic( text ){
  if( ! text ) return '';  
  if( xZip[ text ] ) return xZip[ text ]; else return '"' + text + '"';
}











if (typeof console == 'undefined')
	var console = { debug: function() {}, info: function(txt) {
			if($('#ieconsole')[0]){
				var cons=$('#ieconsole').append(txt.replace('\n','<br>')+'<div class="chatDiv"></div>')[0];
				cons.scrollTop = cons.scrollHeight;
			}
		}
	}
$$ = console.debug
$.MSHTML = $.browser.msie;
$.GECKO = $.browser.mozilla;
$.PRESTO = $.browser.opera;
$.SAFARI = $.browser.safari;

$(document).ready(function(){
	InfoBox.init()
	if (!$.MSHTML)
		Draugiem.Tooltip.load();
})
if ($.MSHTML)
	$(window).load(function(){
		Draugiem.Tooltip.load();
	})

var Draugiem={
	version:'0.1'
}

Draugiem.Tooltip = {
	version: '0.1',
	load: function(el_id){
		if(typeof($.fn.Tooltip)!='undefined'){
			if(!el_id){
				if($('div[title], li[title], a[title], span[title]').size()){
					console.info($('div[title], li[title], a[title][rel!=\'popup\'][rel!=\'infobox\'], span[title]').Tooltip({delay: 0,track: true, showURL: false}).size()+' tooltips added');
				}
				$('#tooltip').hide();
			}else{
				if($('div[title], li[title], a[title], span[title]', $('#'+el_id)).size()){
					console.info($('div[title], li[title], a[title][rel!=\'popup\'][rel!=\'infobox\'], span[title]', $('#'+el_id)).Tooltip({delay: 0, track: true, showURL: false}).size()+' tooltips added');
				}
				$('#tooltip',$('#'+el_id)).hide();
			}
		}
	}
}




// +++ DOM +++
function O2O( obj1, obj2 ){
  if( typeof( obj1 ) == 'undefined' ) return false;
  if( typeof( obj2 ) == 'undefined' ) return false;
  for( var key in obj2 ){
		if( typeof obj2[ key ] == 'undefined' ) console.error( obj2, key );
    if( obj2[ key ].constructor == Object ){
      if( ! obj1[ key ] ) obj1[ key ] = {};
      O2O( obj1[ key ], obj2[ key ] );
    } else {
			obj1[ key ] = obj2[ key ];
    }
  }
  return true;
};

function mkE( par ){
	if( ! par.tag && ! par.text ) return false;
	if( par.tag ){
		var elm = document.createElement( par.tag );
		if( par.attr ) for( key in par.attr ) elm.setAttribute( key, par.attr[ key ] );
		// append childs
		if( par.els && par.els instanceof Array ) for( ii = 0; ii < par.els.length; ii++ ) if( par.els[ ii ] ){
			if( par.els[ ii ].append ) par.els[ ii ].append( elm ); else elm.appendChild( par.els[ ii ] );
		}
		if( par.els && ! par.els instanceof Array ) elm.appendChild( par.els );
		// set properties
		if( par.prop ) O2O( elm, par.prop );
		if( par.id ) elm.id = par.id;
		if( par.className ) elm.className = par.className;
		if( par.style )	O2O( elm.style, par.style );
		if( par.text ) elm.appendChild( document.createTextNode( par.text ) );
		elm.append = mkE.append;
		return elm;
	}
	if( par.text ){
		elm = document.createTextNode( par.text );
		elm.append = mkE.append;
		return elm;
	}
}
mkE.append = function( node ){ node.appendChild( this ); return this; };

function removeNode( node ){
	if( node.parentNode ) return node.parentNode.removeChild( node ); else return false;
	return node;
}
function clearNode( node ){
	var n;
	while( n = node.firstChild ) removeNode( n );
	return node;
}
function addClassName( node, className ){
	var cn = node.className.split( ' ' );
	var is = false;
	for( var i = 0; i < cn.length; i ++ ) if( cn[ i ] == className ) is = true;
	if( ! is ) cn.push( className );
	node.className = cn.join( ' ' );
	return node;
};
function removeClassName( node, className ){
	var cn = node.className.split( ' ' );
	var cnr = [];
	for( var i = 0; i < cn.length; i ++ ) if( cn[ i ] !== className ) cnr.push( cn[ i ] );
	node.className = cnr.join( ' ' );
	return node;
};
function existsClassName( node, className ){
	var cn = node.className.split( ' ' );
	for( var i = 0; i < cn.length; i ++ ) if( cn[ i ] == className ) return true;
	return false;
};
function searchCatOpt() {
	var opt = $('#s_searchCat').val();
	var optText = $('#s_searchCat option[value="'+opt+'"]').text();
	if (optText.length > 20) {
		optText = optText.substr(0,18);
		optText += '..';
	}
	$('#zip_search_form .select_category span').text(optText);
}
function multiSearchCatOpt(select) {
	var name = $(select).attr('name'); 
	var sname = name.replace('[]','');
	var opt = $(select).val();
	var optText = $('select[name="'+name+'"]:first option[value="'+opt+'"]').text();
	/*if (optText.length > 20) {
		optText = optText.substr(0,18);
		optText += '..';
	}*/
	$('u[rel=multiS'+sname+']').text(optText);
}
function multiSearchCheckbox (checkbox) {
	var id = $(checkbox).attr('id'); 
	if ($(checkbox).attr('checked') == '') {
		$('div[rel=multiSC'+id+']').removeClass('checked');	
	}
	else {
		$('div[rel=multiSC'+id+']').addClass('checked');
	}
}
function multiSearchRadio(radio) {
	var name = $(radio).attr('name');
	$('div.radio'+name).removeClass('checked');
	multiSearchCheckbox (radio);
}
// --- DOM ---


// +++ infobox v3 +++
var InfoBox3 = {

	defaults:{
		width:600,
		height:300
	}, // defaults

	init:function( par ){
		var this_ = this;
		if( ! this._ ){
			this._ = {};
			var td;
			this._.node = mkE( {
				tag:'div',
				prop:{
					id:'infobox3',
					style:{
						zIndex:InfoBox.zIndex ++
					}
				},
				els:[
					this._.overlay = mkE( {
						tag:'div',
						prop:{
							id:'infobox3_overlay'
						}
					} ),
					mkE( {
						tag:'table',
						id:'infobox3_content_table',
						els:[
							mkE( {
								tag:'tbody',
								els:[
									mkE( {
										tag:'tr',
										els:[
											td = mkE( {
												tag:'td',
												className:'infobox3Td',
												attr:{
													align:'center',
													valign:'middle'
												}
											} )
										]
									} )
								]
							} )
						]
					} )
				]
			} );
			mkE( {
				tag:'table',
				id:'infobox3_content_table2',
				prop:{
					cellSpacing:'0'
				},
				els:[
					mkE( {
						tag:'tbody',
						els:[
							mkE( {
								tag:'tr',
								els:[
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_tl'
									} ),
									this.title = this._.box_title = mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_tm'
									} ),
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_tr',
										els:[
											mkE( {
												tag:'div',
												prop:{
													style:{
														position:'relative',
														fontSize:'1px',
														width:'1px',
														height:'1px'
													}
												},
												els:[
													this._.closeButton = mkE( {
														tag:'div',
														id:'infobox3_closeButton',
														prop:{
															onclick:function(){
																this_.close();
															},
															onmouseover:function(){
																addClassName( this, 'hover' );
															},
															onmouseout:function(){
																removeClassName( this, 'hover' );
															}
														}
													} ) // div.closeButton
												]
											} ) // div
										]
									} )
								]
							} ), // tr
							mkE( {
								tag:'tr',
								els:[
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_l'
									} ),
									this._.td = mkE( {
										tag:'td',
										className:'infobox3Td',
										els:[
											this._.box = mkE( {
												tag:'div',
												id:'infobox3_box',
												els:[
													this.content = this._.box_content = mkE( {
														tag:'div',
														id:'infobox3_box_content',
														style:{
															position:'relative'
														},
														els:[
															this.contentLite = this._.box_lite = mkE( {
																tag:'div',
																id:'infobox3_box_lite'
															} )
														]
													} )
												]
											} )
										]
									} ),
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_r'
									} )
								]
							} ), // tr
							mkE( {
								tag:'tr',
								els:[
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_bl'
									} ),
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_bm'
									} ),
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_br'
									} )
								]
							} )
						]
					} ) // tbody
				]
			} ).append( td );
		}
		this.setDefaults();
		this.append();
		this._.closeButton.style.display = ( par.withoutClose ? 'none' : '' );
		if( par.withoutFrames ){
			addClassName( this._.node, 'InfoBox3WithoutFrames' );
		} else {
			removeClassName( this._.node, 'InfoBox3WithoutFrames' );
		}
	}, // init:function

	setStyle:function( p ){
		//document.body.style.overflow = p ? 'hidden' : '';
	},

	setDefaults:function(){
		this._.box_content.style.width = '';
		this._.box_content.style.height = '';
		this._.box_lite.style.width = '';
		this._.box_lite.style.height = '';
	}, // setDefaults:function

	close:function(){
		this.type = 'open';
		this.clearAutoResize();
		this.setStyle( false );
		if( this._ && this._.node.parentNode ){
			this.removeNode( this._.node );
			delete this._;
			if( this.onClose ){
				this.onClose();
			}
			return true;
		} else {
			if( window.parent && window.parent !== window && window.parent.InfoBox ){
				return window.parent.InfoBox.close();
			}
			return false;
		}
	}, // close:function

	append:function(){
		document.body.appendChild( this._.node );
	}, // append:function

	clearAutoResize:function(){
		if( this.interval ){
			clearInterval( this.interval );
		}
	},

	autoResize:function(){
		var this_  = this;
		var height = 0;
		this.clearAutoResize();
		var resize = function(){
			switch( this_.type ){
				case 'open':
						var el = this_._.box_content;
						if( el.scrollHeight < document.body.offsetHeight - 50 ){
							el.style.height = 'auto';
							break;
						}
						if( height != el.scrollHeight ){
							var dh = 0;
							if( $.browser.opera ){
								dh = 10;
							}
							this_.resizeTo( this_.par.width, 20 );
							this_.resizeTo( this_.par.width, el.scrollHeight + dh );
							height = el.scrollHeight;
						}
						break;
				case 'iframe':
					try{
						var el = this_._.iframe.contentWindow.document.getElementById( 'iframe_content' );
						el.style.overflow = 'hidden';
						if( height != el.scrollHeight ){
							var dh = 0;
							if( $.browser.opera ){
								dh = 10;
							}
							this_.resizeTo( this_.par.width, el.scrollHeight + dh );
							height = el.scrollHeight;
						}
					} catch( e ){
					}
					break;
				case 'html':
					try{
						var el = this_.content;
						if( height != el.scrollHeight ){
							var dh = 0;
							if( $.browser.opera ){
								dh = 10;
							}
							this_.resizeTo( this_.par.width, 50 );
							this_.resizeTo( this_.par.width, el.scrollHeight + dh );
							height = el.scrollHeight;
						}
					} catch( e ){
					}
					break;
			}
		};
		resize();
		this.interval = setInterval( resize, 500 );
	},

	open:function( href, par ){
		this.type = 'open';
		this.clearAutoResize();
		if( typeof par == 'undefined' ){
			par = {};
		}
		this.par = par;
		this.onClose = ( typeof par == 'object' && par.onClose ? par.onClose : false );
		var this_ = this;
		this.init( par );
		if( par.width && ! par.height ){
			this.content.style.width = par.width + 'px';
			this.content.style.overflow = 'hidden';
		}
		this._.overlay.onclick = function(){};
		this.setStyle( true );
		this.removeNode( this._.box_lite  );
		this._.td.appendChild( this._.box );
		this.clearNode( this._.box_title );
		this.clearNode( this._.box_content );
		this_._.box_content.className = 'load';
		if( typeof par == 'undefined' ) var par = {};
		$.get( href, function( html ){
			if (typeof par.title != 'undefined') {
				this_._.box_title.innerHTML = par.title;
			}
			if( par.onload_resize !== false ){
				if( par.width && par.height ){
					this_.resizeTo( par.width, par.height );
				} else if( par.width && ! par.height ){
					this_.autoResize();
				} else {
					this_.resizeTo( this_.defaults.width, this_.defaults.height );
				}
			}
			this_.content.style.overflow = '';
			this_._.box_content.innerHTML = html;
			this_._.box_content.className = 'with_padding';
			//evalScriptHTML( html );
			if( par.onload ){
				try{
					par.onload.apply( this_ )
				} catch(e){
					D.console.error(e);
				}
			}
		} );
	}, // open:function

	html:function( html, par ){
		this.type = 'html';
		this.clearAutoResize();
		if( typeof par == 'undefined' ){
			par = {};
		}
		this.par = par;
		this.onClose = ( typeof par == 'object' && par.onClose ? par.onClose : false );
		var this_ = this;
		this.init( par );
		this._.overlay.onclick = function(){};
		this.setStyle( true );
		this.removeNode( this._.box_lite  );
		this._.td.appendChild( this._.box );
		this.clearNode( this._.box_content );
		par = par || {};
		if( par.width && par.height ){
			this_.resizeTo( par.width, par.height );
		} else if( par.width && ! par.height ){
			this_.resizeTo( par.width, 100 );
			this_.autoResize();
		} else {
			this_.resizeTo( this_.defaults.width, this_.defaults.height );
		}
		this_._.box_content.innerHTML = html;
		this_._.box_content.className = 'with_padding';
	},

	iframe:function( href, par ){
		this.type = 'iframe';
		this.clearAutoResize();
		if( typeof par == 'undefined' ){
			par = {};
		}
		this.par = par;
		this.onClose = ( typeof par == 'object' && par.onClose ? par.onClose : false );
		var this_ = this;
		this.init( par );
		this._.overlay.onclick = function(){};
		this.setStyle( true );
		this.removeNode( this._.box_lite  );
		this._.td.appendChild( this._.box );
		this.clearNode( this._.box_title );
		if (typeof par.title != 'undefined') {
			this_._.box_title.innerHTML = par.title;
		}
		this.clearNode( this._.box_content );
		this_._.box_content.className = 'load';
		if( typeof par == 'undefined' ) var par = {};
		if( $.browser.msie ){
			try {
				var iframe = this._.iframe = document.createElement( '<iframe onload="if( this.onload_ ){ this.onload_(); }">' );
			}
			catch (err) {
				var iframe = this._.iframe = document.createElement( 'iframe' );	
			}
		} else {
			var iframe = this._.iframe = document.createElement( 'iframe' );
		}
		iframe.frameBorder = '0';
		if( par.width && ! par.height ){
			this.content.style.width = par.width + 'px';
			iframe.style.width = par.width + 'px';
		}
		var needResize = true;
		iframe.onload = iframe.onload_ = function(){
			var height = this.style.height; // IE
			this.style.height = ''; // IE
			this.style.height = height; // IE
			if( ! needResize ){
				return;
			}
			if( par.onload_resize !== false ){
				if( par.width && par.height ){
					this_.resizeTo( par.width, par.height );
				} else if( par.width && ! par.height ){
					this_.resizeTo( par.width, 100 );
					this_.autoResize();
				} else {
					this_.resizeTo( this_.defaults.width, this_.defaults.height );
				}
			}
			iframe.style.visibility = '';
			this_._.box_content.className = '';
			if( par.onload ){
				try{
					par.onload.apply( this_ )
				} catch(e){
					D.console.error(e);
				}
			}
			needResize = false;
		};
		if( par.onload_resize !== false ){
			if( par.width && par.height ){
				this_.resizeTo( par.width, par.height );
			} else if( par.width && ! par.height ){
				this_.autoResize();
			} else {
				this_.resizeTo( this_.defaults.width, this_.defaults.height );
			}
		}
		iframe.src = href;
		this._.box_content.appendChild( iframe );
	}, // iframe:function

	reload:function(){
		if( this.type == 'iframe' ){
			this._.iframe.contentWindow.D.reload();
		}
	},

	openLite:function( par ){
		var this_ = this;
		if( typeof par == 'undefined' ){
			par = {};
		}
		this.par = par;
		this.onClose = par.onClose || false;
		this.init( par );
		this._.overlay.onclick = function(){
			this_.close();
		};
		this.setStyle( true );
		this.removeNode( this._.box  );
		this._.td.appendChild( this._.box_lite );
		this._.box_lite.innerHTML = par.text || '...';
		if( par.width && par.height ) this_.resizeTo( par.width, par.height );
	}, // openLite:function

	resizeTo:function( w, h, par ){
		var this_ = this;
		var w = String( w );
		var h = String( h );
		if( ! par ){
			par = {};
		}
		if( String( w ).indexOf( 'px' ) == -1 && String( w ).indexOf( '%' ) == -1 && w != 'auto' ){
			w = String( Number( w ) + 20 <= document.body.offsetWidth ? Number( w ) + 20 : document.body.offsetWidth - 20 ) + 'px';
		}
		if( String( h ).indexOf( 'px' ) == -1 && String( h ).indexOf( '%' ) == -1 && h != 'auto' ){
			var maxH = document.body.offsetHeight;
			h = String( Number( h ) + 20 <= maxH - 70 ? Number( h ) + 20 : maxH - 70 ) + 'px';
		}
		if( w != 'auto' && h != 'auto' && par.animated ){
			$( this._.box_content ).animate( { width:w, height:h }, 'fast' );
			return
		}
		if( w != 'auto' ){
			this._.box_lite.style.width = w;
			this._.box_content.style.width = w;
			if( this._.iframe ){
				this._.iframe.style.width = w;
			}
		}
		if( h != 'auto' ){
			this._.box_lite.style.height = h;
			this._.box_content.style.height = h;
			if( this._.iframe ){
				this._.iframe.style.height = h;
			}
		}
	}, // resizeTo:function

	removeNode:function( node ){
		if( node.parentNode ) return node.parentNode.removeChild( node ); else return false;
	}, // clearNode:function

	clearNode:function( node ){
		var n;
		while( n = node.firstChild ) this.removeNode( n );
	}, // clearNode:function

	toString:function(){
		return 'dr.lv infobox3';
	} // toString:function
};
// --- infobox v3 ---

// Adapter objekts, lai nodroshinaatu savietojamiibu ar veco Infobox versiju.
var InfoBox = {

	zIndex:1000,
	retVal:false,
	// parametri
	defaults: {close:''},
	// inicializaacija
	init:function(){
	},
	// ajax variants
	open:function( href, props ){
		this.retVal = false;
		InfoBox3.open( href, props );
		return false;
	},

	html:function( html, props ){
		this.retVal = false;
		InfoBox3.html( html, props );
		return false;
	},

	// aizveershana
	close:function(){
		return InfoBox3.close();
	},
	// iframe variants
	iframe:function(href, props){
		this.retVal = false;
		InfoBox3.iframe( href, props );
		return false;
	},

	reload:function(){
		InfoBox3.reload();
		return false;
	},
	// resize
	resizeTo:function(name, x,y, par ){
		InfoBox3.resizeTo( x, y, par );
	}
};

var InfoLite = {
	// loga platums un augstums
	width: 300,
	height: 40,
	defaultWidth: 300,
	defaultHeight: 40,
	wnd: null,
	mode: null,
	text: '...',
	init: function(){
		InfoLite.wnd = $('#infolite');
	},
	open: function(props){
		InfoBox3.openLite( props )
		return false;
	},
	close: function(){
		InfoBox3.close();
	},
	postload: function(){
	},
	resizeto: function(w,h){
		InfoBox3.resizeTo( w, h );
	},
	IEcenter:function(){
	},
	viewport:function(){
	}
}

Draugiem.sayExtPostZip = function( title, url, titlePrefix, domain ){
  window.open(
  domain+'/say/ext/add.php?title=' + encodeURIComponent( title ) +
  '&link=' + encodeURIComponent( url ) +
  ( titlePrefix ? '&titlePrefix=' + encodeURIComponent( titlePrefix ) : '' ),
  '',
  'location=1,status=1,scrollbars=0,resizable=0,width=530,height=400'
 );
 return false;
};





