/*
 * jQuery ifixpng plugin
 */
 var blank = new Image();
 blank.src = 'images/blank.gif';
 
 // Default jQuery Behaviours
$(function() {
	// run the code in the markup!
	$('code.jquery').each(function() {	eval($(this).text());	});
	
	// Add proper quotes to "q" elements
	$("q").prepend("&ldquo;").append("&rdquo;");
	$("q q").prepend("&lsquo;").append("&rsquo;");
	
	// Add classes to input pseudotypes
	$("input[type='text'], input[type='password']").addClass("text");
	$("input[type='text'], input[type='password']").focus(function(){	$(this).addClass("text-focus");	});
	$("input[type='text'], input[type='password']").blur(function(){	$(this).removeClass("text-focus");	});
	$("input[type='button'], input[type='submit'], input[type='checkbox'], input[type='image'], input[type='radio'], input[type='reset'], button").addClass("nontext");
	$("input[type='button'], input[type='submit'], input[type='reset'], button").addClass("button");
	$(".external").attr("target","_blank");	
	
	// Stripe Tables and add Hover to Rows
	$(".stripeMe tr").mouseover(function(){$(this).addClass("hover");}).mouseout(function(){$(this).removeClass("hover");});
	$(".stripeMe tr:even").addClass("alt");

	// Hide elements
	$('#builtBy').hide();
	
	//Add hover to top navigation for IE6
	$('#topNav li').hover(function(){$(this).addClass("hover");}, function(){$(this).removeClass('hover');});
	
	//Add CSS and HTML elements
	$('#topNav ul, .postNav').append('<span class="left"></span><span class="right"></span>');
	$("#bottomNav li").append("&nbsp; &nbsp;")
	
	//Add class of the middle div container to the footer
	var templateClass = $('#middle').attr('class');
	$('body').addClass(templateClass);
	
	// Background Image Animations
	$('#navigation li a').click(function(){
		var myClass = $(this).attr('class');
		$('#background img').fadeOut('fast');
		$('#background img.' + myClass).fadeIn();
	});
	
	// Show next element as an inline popup window
	$("#bubbleInfo li").hover(function(){											  
		$(this).children("div").fadeIn();
    },
	function(){	
		$(this).children("div").hide();
    });
	$('#bubbleInfo').append('<div class="clearfix"></div>');
	$('#bubbleInfo div').append('<span class="arrow"></span>');

	// changer links when clicked
	$("a.changer").click(function(){
	//set the div with class postContent as a var called $mainText 
	var $mainText = $('div.postContent');
	// set the current font size of .postContent as a var called currentSize
	var currentSize = $mainText.css('font-size');
	// parse the number value out of the font size value, set as a var called 'num'
	var num = parseFloat(currentSize, 10);
	// make sure current size is 2 digit number, save as var called 'unit'
	var unit = currentSize.slice(-2);
	// javascript lets us choose which link was clicked, by ID
	if (this.id == 'linkLarge'){
	num = num * 1.1;
	} else if (this.id == 'linkSmall'){
	num = num / 1.1;
	}
	// jQuery lets us set the font Size value of the postContent div
	$mainText.css('font-size', num + unit);
	   return false;
	});
	// hide switchLinks on page load
	$('#switchLinks').hide();
	// show the switchLinks div if showme is clicked
	$('#showMe').click(function(){
	$(this).hide();
	$('#switchLinks').show();
	return false;
	});
	// hide switchlinks if it is clicked
	$('#switchLinks').click(function(){
		$(this).hide();
		$('#showMe').show();
		return false;
	});
	//Behaviour of Terms and Conditions page
	$('#termsConditions #Login').click(function(){
		self.parent.location.href='http://climatecleanauto.com';
		self.parent.tb_remove();
	});

// Plugin Behaviours 
	// Show/Hide title of input
	$("input[type='text']").labelify();
	// Add class="email" and href="mailto:name(at)example.com" to an email address link
	$('.obfuscated').defuscate();
	// Add tooltips to links with class="tooltip" and title="[insert content here]" 
	tooltip();
	// Apply IE6 only Scripts
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (badBrowser) {
		// apply to all png images
		$('img[@src$=.png], #header h1 a, #vinCalculator a').ifixpng(); 
	}
}); // End jQuery Behaviours

