/*-------------------------------------------------------------------------fixIE6flicker-*/
function fixIE6flicker(fix) {
	try {
		document.execCommand("BackgroundImageCache", false, fix);
	} catch(err) { }
}
fixIE6flicker(true);


/*-------------------------------------------------------------------------initHovers-*/
function initHovers(){
	$('#tm_selector .tm_brand').hover(function(){
   		$(this).parent().addClass("curr");
 	},function(){
   		$(this).parent().removeClass("curr");
 	});
}
/*-------------------------------------------------------------------------initCars-*/
function initCars(){
	if($.browser.msie&&$.browser.version<7&&$.browser.version>=5.5){
		$('.carspic').add('.carspic div').each(function(){
			var tmp = $(this).css('backgroundImage');
			var re = /.*\((.+)\).*/;
			var arr = re.exec(tmp);
			var tmp1 = RegExp.$1;
			//alert(tmp1);
			$(this).css('backgroundImage','none').css({filter:'progid:DXImageTransform.Microsoft.AlphaImageLoader (src="'+ tmp1 +'", sizingMethod="crop")'})
		});
	};
	$('.carsmodel').hover(function(){
   		$(this).find('.carspic div').animate({height:122},200);
 	},function(){
   		$(this).find('.carspic div').animate({height:0},400);
 	});

}

/*-------------------------------------------------------------------------initCarPic-*/
function initCarPic(){
	if($.browser.msie&&$.browser.version<7&&$.browser.version>=5.5){
		$('img[@src*=.png]').each(function(){
			var tmp = $(this).attr('src');
			$(this).attr('src','/img/blank.gif').css({filter:'progid:DXImageTransform.Microsoft.AlphaImageLoader (src="'+ tmp +'", sizingMethod="crop")'});
		});
	}
}


/*---------------------------------------------------------------------------------------- initMap */
function initMap(){

	if(typeof(selectedOnStart)!='undefined'){
			oldarea = $('#'+selectedOnStart+'_a').addClass('curr');
			olddealers = $('#'+selectedOnStart+'_d').show();
	}

    $('area').hover(function() {
        $('#'+this.id+'_a').addClass('over');
		$('#tips div').children('div').html(tipsArray[this.id][0]).end().css({left:tipsArray[this.id][1], top:tipsArray[this.id][2]}).show();
    }, function() {
        $('#'+this.id+'_a').removeClass('over');
		$('#tips div').children('div').html('').end().hide();
    }).click(function(){
		$('#'+this.id+'_a').removeClass('over');
		if(typeof(oldarea) != 'undefined'){
			$(oldarea).removeClass('curr');
			$(olddealers).hide();
		}
			oldarea = $('#'+this.id+'_a').addClass('curr');
			olddealers = $('#'+this.id+'_d').show();
		return false;
	});
}

/*---------------------------------------------------------------------------------------- initTrend */
function initTrend(){


    $('area')
		.hover(function() {
			$('#trend div').children('div').html(tipsArray[this.id][0]).end().css({left:tipsArray[this.id][1], top:tipsArray[this.id][2]}).show();
    	}, function() {
			$('#trend div').hide().children('div').html('');
	    })
		.click(function(){return false;});
}


/*---------------------------------------------------------------------------------------- initValigns */
function initValigns(){
	if($.browser.msie&&$.browser.version<7&&$.browser.version>=5){
		$('.c_cont').each(function(){
			var temp = Math.round((parseInt($('.c_wrap').css('height'))-this.offsetHeight)/2);
			$(this).css({marginTop:temp});
		});
		$('.p_cont').each(function(){
			var temp1 = Math.round(($(this).parent('.p_wrap').get(0).offsetHeight - this.offsetHeight)/2);
			$(this).css({marginTop:temp1});
		});
	}
}


/*---------------------------------------------------------------------------------------- initAddInfo */
function initAddInfo(){
	$('a.showDetails')
		.click(function(){
   			$('table.popupTable').addClass('hidden');
			$('a.showDetails').removeClass('hidden');
			$(this).addClass('hidden').next('table').removeClass('hidden');
			return false;
 		});
	$('a.tablecloser')
		.click(function(){
			//console.log($($(this).parents().filter('table')[0]));		
   			$(this).parents().filter('table.popupTable').addClass('hidden').prev('a.showDetails').removeClass('hidden');
			return false;
 		});

}


/*---------------------------------------------------------------------------------------- initHighlights */


function initHighlights(){
	//$('body').append('<div id="debug" style="position:absolute; top:0; right:0; padding:40px; border:4px solid red;"></div>');
	$("a[@href*=#]").bind('click',function(){
		var a_id = $(this).attr('href');


		if($.browser.msie){
			$(a_id).animate({background:'#ff9'},1000,function(){
				$(a_id).animate({background:'#eee'},1000)
				$(a_id).css({background:'none'})
			})
		}
		else {
			var old_bgc = $(a_id).css('backgroundColor');
			$(a_id).Highlight(1500, '#ffff99');
			$(a_id).css('backgroundColor',old_bgc);
			$(a_id).css('background',old_bgc);
		}
		return true;
	})
}





/*-------------------------------------------------------------------------initCars2-*/
function initCars2(){
	if($.browser.msie&&$.browser.version<7&&$.browser.version>=5.5){
		$('.carspic').each(function(){
			var tmp = $(this).css('backgroundImage');
			var re = /.*\"(.+)\".*/;
			var arr = re.exec(tmp);
			var tmp1 = RegExp.$1;
			//alert(tmp1);
			$(this).css('backgroundImage','none').css({filter:'progid:DXImageTransform.Microsoft.AlphaImageLoader (src="'+ tmp1 +'", sizingMethod="crop")'})
		});
	};
}


/* Для збільшених зображень */
function showPic(src, ttl, iWidth, iHeight)
{
var windowprops = "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no,left=300,top=80,width=" + iWidth + ",height=" + iHeight;
a = window.open("","popup",windowprops);
a.document.open();
a.document.write('\n' +
'<html>\n' +
'<head><title>' + ttl + '</title>\n' +
'<style>\n' +
'* {margin:0; padding:0;}\n' +
'body {height:100%; background-color:#889;}\n' +
'</style>\n' +
'</head>\n' +
'<body>\n' +
'<a href="javascript:window.self.close();"><image src="' + src + '" width="' + iWidth + '" height="' + iHeight + '" alt="Закрыть окно" border="0"></a>\n' +
'</body>\n</html>\n');
a.document.close();
}

