function fixPNG(element) {
    if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
        var src;

        if (element.tagName=='IMG') {
            if (/\.png$/.test(element.src)) {
                src = element.src;
                element.src = "/images/1.gif";
            }
        } else {
            src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
            if (src) {
                src = src[1];
                element.runtimeStyle.backgroundImage="none";
            }
        }
        if (src) {
            element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', scale='crop')";
        }
    }
}

function addBookmark(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;
  return true;
}


var cssFix = function(){
  var u = navigator.userAgent.toLowerCase(),
  addClass = function(el,val){
    if(!el.className) {
      el.className = val;
    } else {
      var newCl = el.className;
      newCl+=(" "+val);
      el.className = newCl;
    }
  },
  is = function(t){return (u.indexOf(t)!=-1)};
  addClass(document.getElementsByTagName('html')[0],[
    (!(/opera|webtv/i.test(u))&&/msie (\d)/.test(u))?('ie ie'+RegExp.$1)
      :is('firefox/2')?'gecko ff2'
      :is('firefox/3')?'gecko ff3'
      :is('gecko/')?'gecko'
      :is('opera/9')?'opera opera9':/opera (\d)/.test(u)?'opera opera'+RegExp.$1
      :is('konqueror')?'konqueror'
      :is('applewebkit/')?'webkit safari'
      :is('mozilla/')?'gecko':'',
    (is('x11')||is('linux'))?' linux'
      :is('mac')?' mac'
      :is('win')?' win':''
  ].join(" "));
}();



window.addEvent('domready', function(){ 

	/*['table','td','tr'].each(function(tag){
		$('main_view').getElements(tag).each(function(item, index){
				item.set('width', ''); 
				//item.setStyle('width', '100%');
			});
		});*/
		
		
    ['login_login', 'login_password', 'search_string'].each(function(id){
		var elem = $(id);
		if( !elem ) return;
		if(elem.get('value').length == 0) 
		{
			elem.setStyle('background','none');
		} 
		
		elem.addEvent('focus', function(){ elem.setStyle('background','#fbfae8'); });
		elem.addEvent('blur', function()
		{ 
			if(elem.get('value').length == 0) 
			{
				elem.setStyle('background','none');
			} 
		});
	});
    
    
	///////////////////////////////////////////
	// Отработка большого контентного блока
	var mv_width=$('main_view').getCoordinates().width;
	var mv_left=$('main_view').getCoordinates().left;
	var page_width=$('all').getCoordinates().width;
	var max = mv_width;
	
	
	
	// ищем максимальную ширину блока для заданных тэгов
	['table','img','p','span', 'div'].each(function(tag){
		$('main_view').getElements(tag).each(function(item, index){
		
				//alert(index + " = " + item);
				if(item.getCoordinates().width > max) max=item.getCoordinates().width;
			});
		});
	
		
	if(max>mv_width)
	{
		// Увеличиваем страницу
		$('all').setStyle('width', max - mv_width + page_width);
		// устанавливаем координаты контентного блока
		$('main_view').setStyle('width', max);
		
		
	}
	
	 
});




