$(document).ready(function(){	
	// Hover buttons:
	$('.hover').hover(function() {
		pi_imageOver($(this));									
	}, function() {
		pi_imageOut($(this));
	});	
	
	// Expandable blocks:
	$(".pi-expandable").each(function(index) {
		// Put the right button according to the expandable area:
		if ($(this).parent().find('.pi-expand-area').is('.pi-expanded')) {
			$(this).addClass("pi-collapse-button");	
		}
		else {
			$(this).addClass("pi-expand-button");			
		}
	}).click(function() {
		if ($(this).is(".pi-expand-button")) {
			// Collapse all:
			if (!$(this).is(".pi-disclaimer-title")) {
				$(this).parent().parent().parent().find('.pi-expand-area').slideUp();
				$(this).parent().parent().parent().find('.pi-expandable').removeClass("pi-collapse-button").addClass("pi-expand-button");
			}
			
			// Expand this one only:
			if (pi_isIE6()) {
				$(this).parent().find('.pi-expand-area').show();
			}
			else {
				$(this).parent().find('.pi-expand-area').slideDown();
			}
			$(this).removeClass("pi-expand-button").addClass("pi-collapse-button");
		}
		else {
			// Collapse:
			if (pi_isIE6()) {
				$(this).parent().find('.pi-expand-area').hide();
			}
			else {
				$(this).parent().find('.pi-expand-area').slideUp();
			}
			$(this).removeClass("pi-collapse-button").addClass("pi-expand-button");
		}
	});
	
	// Expand-Collapse All:
	$("#pi-expand-collapse").click(function() {
		if ($(this).find('.expand-all').is(":visible")) {
			if (pi_isIE6()) {
				$('.pi-expand-area').show();
			}
			else {
				$('.pi-expand-area').slideDown();
			}
			$('.pi-expandable').removeClass("pi-expand-button").addClass("pi-collapse-button");
			$(this).find('.expand-all').hide();
			$(this).find('.collapse-all').show();
		}
		else {
			$('.pi-expand-area').slideUp();
			$('.pi-expandable').removeClass("pi-collapse-button").addClass("pi-expand-button");
			$(this).find('.collapse-all').hide();
			$(this).find('.expand-all').show();			
		}
		return false;
	});
		
	// Expandable blocks (small panels):
	/*$(".pi-expandable").click(function(){
		if ($(this).is(".pi-expand-button")){
			var pdtpanel = false;
			var minheight = 0;
			if ($(this).parent().find(".pi-expand-area").is(".pi-product-panel-topcontent")){
				pdtpanel = true;
				minheight = parseInt($(this).parent().find(".pi-expand-area").css("min-height"));
				$(this).parent().find(".pi-expand-area").css("min-height",0);
			}
			$(this).parent().find(".pi-expand-area").slideDown("fast",function(){
				if (pdtpanel){
					$(this).css("min-height",minheight);
				}
				
			});
			$(this).removeClass("pi-expand-button").addClass("pi-collapse-button");
		}
		else {
			var pdtpanel = false;
			var minheight = 0;
			if ($(this).parent().find(".pi-expand-area").is(".pi-product-panel-topcontent")){
				pdtpanel = true;
				minheight = parseInt($(this).parent().find(".pi-expand-area").css("min-height"));
				$(this).parent().find(".pi-expand-area").css("min-height",0);
			}
			$(this).parent().find(".pi-expand-area").slideUp("fast",function(){
				if (pdtpanel){
					$(this).css("min-height",minheight);
				}
			});
			
			$(this).removeClass("pi-collapse-button").addClass("pi-expand-button");
		}
	});*/
}); 


// Image roll-overs (change the image src):
function pi_imageOver($image) {
	var src = $image.attr("src");
	if (src.substr(-9,5) != "_over") {			
		$image.attr("src",src.substr(0,src.length-4)+"_over.png");
		if ($.browser.msie && $.browser.version <= 6) DD_belatedPNG.fixPng($image[0]);			
	}
}

function pi_imageOut($image) {
	var src = $image.attr("src");
	if (src.substr(-9,5) == "_over") {
		$image.attr("src",src.substr(0,src.length-9)+".png");
		if ($.browser.msie && $.browser.version <= 6) DD_belatedPNG.fixPng($image[0]);					
	}
}


// Utils:
function pi_isIE6() { return false; /*($.browser.msie && $.browser.version <= 6);*/ }
