
$(document).ready(function() {
    if ((setProductType.indexOf('pub') > 0) || (setProductType.indexOf('vis') > 0) || (setProductType.indexOf('word') > 0) || (setProductType.indexOf('excel') > 0) || (setProductType.indexOf('proj') > 0) || (setProductType.indexOf('pow') > 0) || (setProductType.indexOf('one') > 0) || (setProductType.indexOf('out') > 0) || (setProductType.indexOf('access') > 0) || (setProductType.indexOf('pack') > 0) || (setProductType.indexOf('upg') > 0)) {
        showPKC = "false"
        $('div.priceArea')[0].style.display = "block";
        $('.pkc_header')[0].style.display = "none";
        $('.pkc_body').css('background', 'none');
        $('.pkc_body').css('width', 'auto');
        $('div.pkc_body .pkc_btn').css('float', 'left');
        $('div.pkcwrapper .productDownload .prodBuyNowBtn').css('float', 'left');
        $('.pkc_bottom')[0].style.display = "none";
        $('div.pkc_body .radio')[0].style.display = "none";
        $('div.prodLangDropdown')[0].style.display = "none";
        $('div.pkc_body')[0].style.display = "block";
    }

    if (isPKC == "true" && showPKC == "true") {
        $('div.radio').css('display', 'block');
        $('div.pkc_body')[0].style.display = "block";
        $(".prodLangDropdown").css('display', 'block');
    }
    else {
        if ($('.trialSticker')[0]) {
            $('.trialSticker')[0].style.display = "block";
            $('.pkc_header')[0].style.display = "none";
            $('.pkc_body').css('background', 'none');
            $('.pkc_bottom')[0].style.display = "none";
            $('div.pkc_body')[0].style.display = "block";
        }
    }
    if ($.browser.msie) {
        $('input:radio').click(function() {
            this.blur();
            this.focus();
        });
    }

    $('.toolTip').hover(
    	function() {
    	    this.tip = this.title;
    	    $(this).after(
     			'<div class="toolTipWrapper">'
        	+ '<div class="toolTipLeft"></div>'
        	+ '<div class="toolTipMid">'
          + this.tip
       	 	+ '</div>'
        	+ '<div class="toolTipRight"></div>'
      		+ '</div>'
    		);
    	    this.title = "";
    	    var pos = $(this).position();
    	    this.width = $(this).width();
    	    $('.toolTipWrapper').css({ left: pos.left + 20 });
    	    $('.toolTipWrapper').css({ top: pos.top - 25 });
    	    $('.toolTipWrapper').fadeIn(300);
    	},
    	function() {
    	    $('.toolTipWrapper').fadeOut(100);
    	    $(this).next(".toolTipWrapper").remove();
    	    this.title = this.tip;
    	}
  	);
});

	$langsAreNotMirrored = true;	// set to false when the dropdowns don't contain the same set of langs
	$("input[name='radio_price']").change(
		function() {
		    if ($("input:radio[name='radio_price']:checked").val() == 'std') {
		        $(".standardBuy").css('display', 'block');
		        $(".extBuy").css('display', 'none');
		        $(".prodLangDropdown").css('display', 'block');
		        $(".extProdLangDropdown").css('display', 'none');
				
				if($langsAreNotMirrored)
			        $(".prodLangDropdown .innerInput").val($(".extProdLangDropdown option:selected").val());
				
				if(typeof $(".prodLangDropdown .innerInput option:selected").val() == 'undefined') {
					defaultToSelectNextAvailLang(".prodLangDropdown .innerInput");
					$langsAreNotMirrored = false;
				}
		    }
		    if ($("input:radio[name='radio_price']:checked").val() == 'upd') {
		        $(".extBuy").css('display', 'block');
		        $(".standardBuy").css('display', 'none');
		        $(".extProdLangDropdown").css('display', 'block');
		        $(".prodLangDropdown").css('display', 'none');
				
				if($langsAreNotMirrored)
			        $(".extProdLangDropdown .innerInput").val($(".prodLangDropdown option:selected").val());
				
				if(typeof $(".extProdLangDropdown .innerInput option:selected").val() == 'undefined') {
					defaultToSelectNextAvailLang(".extProdLangDropdown .innerInput");
					$langsAreNotMirrored = false;
				}
		    }
		}
	);
	
	var productbc;
	
	productbc = $('.productName')[0].innerHTML;

	$(document).ready(function() {
	    var productbcSup
	    if (productbc.indexOf("<sup>") > 0) {
	        productbcSup = (productbc.replace("<sup>", ""));
	        productbcSup = (productbcSup.replace("</sup>", ""));
	        $('.productname')[0].innerHTML = productbcSup;
	    }
	    else {
	        if (productbc.indexOf("<SUP>") > 0) {
	            productbcSup = (productbc.replace("<SUP>", ""));
	            productbcSup = (productbcSup.replace("</SUP>", ""));
	            $('.productname')[0].innerHTML = productbcSup;
	        }
	        else {
	            $('.productname')[0].innerHTML = productbc;
	        }
	    }

	    var stdlang = $('.prodLangDropdown select')[0].value;
	    var stdprice = ($('#product_base_' + stdlang).attr('value'));
	    $("div.std_price").html(stdprice);
	    var updlang = $('.extProdLangDropdown select')[0].value;
	    var updprice = ($('#product_' + updlang + '_ext').attr('value'));
	    $("div.upd_price").html(updprice);
	    $(".torb4updprice").html(stdprice);

	    $('input[id="main_std"]').attr('checked', true);
	    $('input[id="sub_std"]').attr('checked', true);

	    //var productlang;
	    productlang = $('.prodLangDropdown select.innerInput')[0];

	    if (productlang && productlang != "") {
	        if ($('.prodLangDropdown select.innerInput option').length > 1) {
	            //$('.fakeProdLang')[0].innerHTML = productlang;
	            $('.prodLangDropdown select.innerInput').clone().prependTo('.prodlangSelect');
	            $('.prodlangSelect select').removeAttr("id");
	            $('.prodlangSelect select').removeAttr("name");
	            //$('.prodlangSelect select').attr("onchange", "switchProdLang()");
	            $('.prodlangSelect select').change(function() {
	                switchProdLang();
	            });
	            //$('.prodLangMiniDesc')[0].style.display = "block";
	            switchPrice();
	        }
	        else {
	            $('.prodLangMiniDesc')[0].style.display = "block";
	        }
	    }
	    else {
	        $('.prodLangMiniDesc')[0].style.display = "block";
	    }



	    var tab1Image = $('.innerTabTable img.tabImage')[0];
	    var tab2Image = $('.innerTabTable img.tabImage')[1];
	    var tab3Image = $('.innerTabTable img.tabImage')[2];
	    if (tab1Image) {
	        $('.innerTabTable td')[0].style.width = tab1Image.clientWidth + 'px';
	        if ($('img.blantab2class')[0]) {
	            $('img.blantab2class')[0].style.display = 'none';
	        }
	    }
	    if (tab2Image) {
	        $('.innerTabTable td')[1].style.width = tab2Image.clientWidth + 'px';
	        if ($('img.blantab2class')[1]) {
	            $('img.blantab2class')[1].style.display = 'none';
	        }
	    }
	    if (tab3Image) {
	        $('.innerTabTable td')[2].style.width = tab3Image.clientWidth + 'px';
	        if ($('img.blantab2class')[2]) {
	            $('img.blantab2class')[2].style.display = 'none';
	        }
	    }
	    if ($('.innerTabTable')[2]) {
	        $('.innerTabTable td')[0].style.width = tab1Image.clientWidth + 'px';
	        $('.innerTabTable td')[4].style.width = tab1Image.clientWidth + 'px';
	        $('.innerTabTable td')[8].style.width = tab1Image.clientWidth + 'px';
	        $('.innerTabTable td')[1].style.width = tab2Image.clientWidth + 'px';
	        $('.innerTabTable td')[5].style.width = tab2Image.clientWidth + 'px';
	        $('.innerTabTable td')[9].style.width = tab2Image.clientWidth + 'px';
	    }
	    else {
	        if ($('.innerTabTable')[1]) {
	            $('.innerTabTable td')[0].style.width = tab1Image.clientWidth + 'px';
	            $('.innerTabTable td')[3].style.width = tab1Image.clientWidth + 'px';
	        }
	        else {
	            //alert('1 table');
	        }
	    }

	    // Set the text above where the dropdown should be if there's only one language there - since DD will be hidden
	    $prodDDLen = $('.prodLangDropdown select option').length;
	    $extProdDDLen = $('.extProdLangDropdown select option').length;
	    if ($prodDDLen == 1 && $extProdDDLen == $prodDDLen) {
	        $('.pkc_dropdown').prepend('<span>' + $('select.languageSelect option:selected').text() + '</span>');
	        $prodDDText = getOnlyText('.prodLangDropdown');
	        $extProdDDText = getOnlyText('.extProdLangDropdown');
	        setOnlyText('.prodLangDropdown', $.trim($prodDDText.substr(2, $prodDDText.length)));
	        setOnlyText('.extProdLangDropdown', $.trim($extProdDDText.substr(2, $extProdDDText.length))); // IE8 does not support .trim() :(
	    }
	});

	function switchProdLang() {
	  var lang = $('.prodlangSelect select')[0].value;
		$('.prodLangDropdown .innerInput')[0].value = lang;
		switchPrice();
	}
	
	function switchPrice() {
	  var displayPrice = $('.price .amt')[0];
	  var lang = $('.prodlangSelect select')[0].value;
		var price = document.getElementById('product_base_' + lang);
		if (price && displayPrice) {
			displayPrice.innerHTML = price.attributes['value'].value;
		}
	}
	
	function defaultToSelectNextAvailLang(selector) {
		$(selector + ' option').each(function() {
			if(typeof $(this).val() != 'undefined') {
				$(this).attr('selected', 'selected');
				return true;	
			}
		});
	}
	
	// Gets only the text from the top level container and none of the child node data
	function getOnlyText(selector) {
		if(typeof $(selector) != 'undefined')
			return $(selector).clone().children().remove().end().text();
		else
			return '';
	};
	
	// Gets only the text from the top level container and none of the child node data
	function setOnlyText(selector, newText) {
		if(typeof $(selector) != 'undefined')
			$(selector).get(0).lastChild.nodeValue = newText;
	};
