﻿var popupStatus = 0;
var popupID = '';
function loadPopup(pID) {
    popupID = pID;
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("fast");
		$("#" + popupID).fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("fast");
		$("#" + popupID).fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(pID) {
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#" + pID).height();
	var popupWidth = $("#" + pID).width();
	//centering
	$("#" + pID).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
$(document).ready(function(){
	initPopup();
});

function initPopup(){
    $("#selGuide").click(function() {
		$('#selGuideImg').html('<img src="img/SelectionGuide.gif" alt="Exedy Selection guide" />');
    		centerPopup('popupSelGuide');
		loadPopup('popupSelGuide');
    });

    $("#pullType").click(function() {
	$('#pullTypeImg').html('<img src="img/Pull-Type.gif" alt="Pull Type" />');
        centerPopup('popupPull');
        loadPopup('popupPull');
    });
    $("#releaseBearing").click(function() {
	    var a = $(this)[0];
            var link = $(a).attr('link');
	$('#bearingImg').html('<img src="productImages/web_' + $(a).attr('link') + '.jpg" alt="Pull Type" />');
        centerPopup('bearing');
        loadPopup('bearing');
    });
	
	$(".closePopup").click(function(){
		disablePopup();
	});
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
}
