
//png fixing


if (IE6) {
	
	$('.topInfo .fuel').css({
   	'background-image':'url("common/phpthumb/phpThumb.php?src=http://ww3.ldvis.com/den_suzuki/img/trim/fuel_logo.png&w=90&f=gif")'
   });
   
   $('.trim_container .factsbox').css({
   	'background-image':'url("common/phpthumb/phpThumb.php?src=http://ww3.ldvis.com/den_suzuki/img/trim/right_bg.png&w=8&f=gif")'
   });
	
	$('.results .output').css({
		'min-height':'50px',
		'height': 'auto !important',
		'height': '50px'
	});
	$('.drop').css({'background':'#d8dce7 url("") top left no-repeat','border':'1px solid #609abf'});
    
	var mainSrc = $('#mainImg').attr('src');
	$('#mainImg').attr('src','common/phpthumb/phpThumb.php?src='+mainSrc+'&w=400&f=gif');
	
	jQuery(this).find("img[src$=.png]").each(function(){
    
        jQuery(this).attr('width', jQuery(this).width());
        jQuery(this).attr('height', jQuery(this).height());
        
        var prevStyle = '';
        var strNewHTML = '';
        var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
        var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
        var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
        var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
        var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
        var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
		var imgPos = $(this).css('position');
		var imgView = ($(this).css('display') === 'none') ? 'none' : 'inline-block';
        if (this.style.border) {
            prevStyle += 'border:' + this.style.border + ';';
            this.style.border = '';
        }
        if (this.style.padding) {
            prevStyle += 'padding:' + this.style.padding + ';';
            this.style.padding = '';
        }
        if (this.style.margin) {
            prevStyle += 'margin:' + this.style.margin + ';';
            this.style.margin = '';
        }
        var imgStyle = (this.style.cssText);
        
        strNewHTML += '<span ' + imgId + imgClass + imgTitle + imgAlt;
        strNewHTML += 'style="position:'+imgPos+';white-space:pre-line;display:'+imgView+';background:transparent;' + imgAlign + imgHand;
        strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
        strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
        strNewHTML += imgStyle + '"></span>';
        if (prevStyle != '') {
            strNewHTML = '<span style="position:relative;display:inline-block;' + prevStyle + imgHand + 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;' + '">' + strNewHTML + '</span>';
        }
        
        
        jQuery(this).after(strNewHTML);
		jQuery(this).remove();
    });
    
    
    $('body').find("*").each(function(){
        var bgIMG = $(this).css('background-image');
        if (bgIMG.indexOf(".png") != -1 && bgIMG.indexOf("&f=gif") == -1) {
            var iebg = bgIMG.split('url("')[1].split('")')[0];
			var content = $(this).html();
			var width = $(this).outerWidth();
			var height = $(this).outerHeight();
            $(this).css({
				'background-image': 'none',
				'background-position':'0px 0px'
			});
			$(this).prepend('<div class="bgcopy"></div>');
			$(this).find('.bgcopy').css({
				"position":"absolute",
				"width":width+'px',
				"height":height+'px',
				"filter":"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')",
				"top":"0px",
				"left":"0px",
				"z-index":"0"
			});
        }
    });
	

	$('body').find("input[src$=.png]").each(function() {
		var bgIMG = jQuery(this).attr('src');
		jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', 'img/blank.gif');
	});
}



//active nav

var pageName = $.url('all');
var tabs = new Array();

$('.navbar .link').each(function(){
    var linkIndex = $('.navbar .link').index(this);    
    
	if (pageName.indexOf('index.php') == -1 && pageName.indexOf('specials.php') == -1 && pageName.indexOf('inventory.php') == -1) {
            $(this).find('a').each(function(){
				var theLink = $(this).attr('href');
	            if (theLink.indexOf(pageName) != -1) {
	                tabs.push(linkIndex);
	            }
			});			
    }
	else if (pageName.indexOf('specials.php') != -1){
		tabs.push('3');
	}
	else if (pageName.indexOf('compare') != -1){
		tabs.push('4');
	}
	else if (pageName.indexOf('inventory.php') != -1){
		if(pageName.indexOf('t=N') != -1){
			tabs.push('4');
		}
		else if(pageName.indexOf('t=U') != -1){
			tabs.push('5');
		}else if(pageName.indexOf('t=C') != -1){
			tabs.push('6');
		}
	}
    else {
        tabs.push('0');
    }
});

var lastEdit = tabs.pop();
if(lastEdit) $('.navbar .link:eq(' + lastEdit + ')').css('background-position','0px -39px').attr('id','active');



//nav

$('.link').hover(function(){
	menu = $(this).find('.drop');
	$(menu).show();
	if($(this).find('span:eq(0)').is(':not(:contains("specials"))')){
		$(this).css('background-position','0px -39px');
	}
},function(){
	menu = $(this).find('.drop');
	$(menu).hide();
	if($(this).find('span:eq(0)').is(':not(:contains("specials"))')){
		if($(this).is(':not(#active)')){
			$(this).css('background-position','0px 0px');
		}
	}
});

$('.noFollow').bind('click',function(){
	return false;
});


//forms
$('input[type=text],textarea,select').data('selected','false');


$('input[type=text],textarea,select').not('.clearInput').bind('focus',function(){
	$('input[type=text]:data(selected=true),textarea:data(selected=true),select:data(selected=true)').data('selected','false').css('border-color','#83a1bb');
	$(this).data('selected','true').css('border-color','#9b9b9b');
	$(this).unbind('mouseleave').unbind('mouseenter');
	$.selectDefine();
});

$('.clearInput').each(function(){
	$(this).data('init',$(this).val());
});

$('.clearInput').bind('keypress',function(){
	$(this).data('selected','true');
});

$('.clearInput').bind('focus',function(){
	if($(this).data('selected') == 'false'){
		$(this).val('');
	}
	
	$('.clearInput').not(this).each(function(){
		if($(this).val() == ''){
			$(this).val($(this).data('init'));
		}
	});
	
});

