/*
* Name: jquery.
* Version: 0.1
*/
(function($) {
    $.linkGenerator = {
        defaults: {
			languageObj: "",
			currencyObj: "",
			licenseObj: "",
			paymentObj: ""
        },
        
		linkGeneratorInit: function(opts) {
			return this.each(function() {
                this.opts = {};
                $.extend(this.opts, $.linkGenerator.defaults);
                $.extend(this.opts, opts);
				
				var linkGenerator = this,
				languageObj = linkGenerator.opts.languageObj,
				currencyObj = linkGenerator.opts.currencyObj; 
				
				var link;
				
				//var paymentSystem;
				var licenseType;
				
				//var idxOfPS;
				var idxOfPT;
				var idxOfLT;
				
				//var arrKeysPaymentSystems = [
				//	"psSoftkey"
				//];
				var arrValuesPaymentSystems = [
					"http://www.softkey.ua/catalog/basket.php?from=542911&prodid="
				];
				
				var arrProductTypes = [
					"ptTNI"
				];
				
				var arrLicenseTypes = [
					"tni25",
					"tni50",
					"tni100",
					"tni150",
					"tni250",
					"tni350",
					"tni500",
					"tniNationwide",
					"tniWorldwide",
					"tniMSP"
			    ];
				
				/* ---------- */
				
				var productIDs = [
					[
						[ 
							'99204',
							'99209',
							'99210',
							'99213',
							'99218',
							'99223',
							'99226',
							'99228',
							'150667',
							'132744' // Product ID
						] // Product type
					] // Payment system
				];

				$(linkGenerator).bind("click", function() {
					
					licenseType = $(linkGenerator).parentsUntil(".tabs-content").find(linkGenerator.opts.licenseObj).attr("value");
					//paymentSystem = $(linkGenerator).parentsUntil(".tabs-content").find(linkGenerator.opts.paymentObj).attr("value");
					
					//for (i = 0; i < arrKeysPaymentSystems.length; i++) {
					//	if (arrKeysPaymentSystems[i] == paymentSystem) {
					//		idxOfPS = i;
					//	}
					//}
					idxOfPT = 0;
					for (i = 0; i < arrLicenseTypes.length; i++) {
						if (arrLicenseTypes[i] == licenseType) {
							idxOfLT = i;
						}
					}
					
					//link = arrValuesPaymentSystems[idxOfPS] + productIDs[idxOfPS][idxOfPT][idxOfLT];
					link = arrValuesPaymentSystems[0] + productIDs[0][idxOfPT][idxOfLT];
				
					window.location.href = link;
					
					return false;
				});
			});
		
		}

	};
    $.fn.linkGenerator = $.linkGenerator.linkGeneratorInit;
	
	$("#linkPayment1").linkGenerator({
		languageObj: "#selectedLanguage",
		currencyObj: "#selectExchangeRate1",
		licenseObj: "input[name='radio-a']:checked",
		paymentObj: "input[name='radio-b']:checked"
	});
	$("#linkPayment2").linkGenerator({
		languageObj: "#selectedLanguage",
		currencyObj: "#selectExchangeRate2",
		licenseObj: "input[name='radio-c']:checked",
		paymentObj: "input[name='radio-d']:checked"		
	});
	
})(jQuery);
