(function($){

	$.fn.anniversaryPicker = function(options){
	
		var opts = $.fn.extend({},$.fn.anniversaryPicker.defaults, options);
		
		return this.each(function(){
			
				
				$(opts.txtArea).html("Select a year from the dropdown to view what gift to give for that anniversary.");
			
				var $form = $("<form name='anniversaryForm' id='anniversaryForm' method='post' action='#' ></form>");
				
				var dropdown =  $("<select name='yearVal' id='yearVal' ><option value=''>Choose a year</option></select>");
				for(var i = 1; i < 16; i++){ 
					if(i == 1){
						dropdown.append("<option value='"+ i +"'>"+ i +" year</option>");
					}else{
						dropdown.append("<option value='"+ i +"'>"+ i +" years</option>");
					}
				}
						
				dropdown.append("<option value='20'>20 years</option>");
				dropdown.append("<option value='25'>25 years</option>");
				dropdown.append("<option value='30'>30 years</option>");
				dropdown.append("<option value='35'>35 years</option>");
				dropdown.append("<option value='40'>40 years</option>");
				dropdown.append("<option value='45'>45 years</option>");
				dropdown.append("<option value='50'>50 years</option>");
				dropdown.append("<option value='55'>55 years</option>");
				dropdown.append("<option value='60'>60 years</option>");
				
				var radioButtons = $("<input type='radio' checked='checked' name='giftType' id='giftType1' value='traditional' />&nbsp;<label for='giftType1' >Traditional</label>&nbsp;&nbsp;<input type='radio' name='giftType' id='giftType2' value='modern' />&nbsp;<label for='giftType2'>Modern</label>");
				
				var tableWrapper = $("<table cellspacing='0' cellpadding='0' width='100%'><tr><td></td><td></td></tr></table>");
				
				tableWrapper.find("td:eq(0)").append(dropdown);
				tableWrapper.find("td:eq(1)").append(radioButtons);
				
				$form.append(tableWrapper);
				$(opts.formArea).append($form);
				
				// add functionality to dropdown
				$(opts.dropdown).change(function(){
					var selectedYear = $(this).val();
					var giftType = $("input[name="+opts.giftType+"]:checked").val();
					
					$.fn.anniversaryPicker.checkGift(selectedYear,giftType,opts.txtArea);
					
				});
				
				// add functionality to radio buttons
				$("input[name="+opts.giftType+"]").click(function(){
					var selectedYear = $(opts.dropdown).val();
					var giftType = $("input[name="+opts.giftType+"]:checked").val();
					
					$.fn.anniversaryPicker.checkGift(selectedYear,giftType,opts.txtArea);
					
				});
				
		});
	
	};//anniversaryPicker
	
	$.fn.anniversaryPicker.checkGift = function(selectedYear,giftType,txtArea){
		
		
		//trad gifts
		var tradGifts = new Array();
		tradGifts[1] = "Paper";
		tradGifts[2] = "Cotton";
		tradGifts[3] = "Leather";
		tradGifts[4] = "Fruit/Flowers";
		tradGifts[5] = "Wood";
		tradGifts[6] = "Candy/Iron";
		tradGifts[7] = "Wool/Copper";
		tradGifts[8] = "Bronze/Pottery";
		tradGifts[9] = "Pottery/Willow";
		tradGifts[10] = "Tin/Aluminium";
		tradGifts[11] = "Steel";
		tradGifts[12] = "Silk/Linen";
		tradGifts[13] = "Lace";
		tradGifts[14] = "Ivory";
		tradGifts[15] = "Crystal";
		tradGifts[20] = "China";
		tradGifts[25] = "Silver";
		tradGifts[30] = "Pearl";
		tradGifts[35] = "Coral";
		tradGifts[40] = "Ruby";
		tradGifts[45] = "Sapphire";
		tradGifts[50] = "Gold";
		tradGifts[55] = "Emerald";
		tradGifts[60] = "Diamond";
		
		// modern gifts
		var modernGifts = new Array();
		modernGifts[1] = "Clocks";
		modernGifts[2] = "China";
		modernGifts[3] = "Crystal/Glass";
		modernGifts[4] = "Appliances";
		modernGifts[5] = "Silverware";
		modernGifts[6] = "Wood";
		modernGifts[7] = "Desk Sets";
		modernGifts[8] = "Linens/Lace";
		modernGifts[9] = "Leather";
		modernGifts[10] = "Diamond Jewellery";
		modernGifts[11] = "Fashion Jewellery";
		modernGifts[12] = "Pearls";
		modernGifts[13] = "Textiles/Furs";
		modernGifts[14] = "Gold Jewellery";
		modernGifts[15] = "Watches";
		modernGifts[20] = "Platinum";
		modernGifts[25] = "Silver";
		modernGifts[30] = "Diamond";
		modernGifts[35] = "Jade";
		modernGifts[40] = "Ruby";
		modernGifts[45] = "Sapphire";
		modernGifts[50] = "Gold";
		modernGifts[55] = "Emerald";
		modernGifts[60] = "Diamond";
		
		var typeTxt = "";
		var giftVal = "";
		
		if( selectedYear != ""){
			if( giftType == "traditional" ){
					giftVal = tradGifts[selectedYear];
					typeTxt = "traditional";
			}//if
			else{
				giftVal = modernGifts[selectedYear];
				typeTxt = "modern";
			}//else
			
			$(txtArea).html("The <span>"+ typeTxt +"</span> gift for the <span class='largeText'>"+ selectedYear +"</span> year anniversary is: <span class='largeText'>"+ giftVal +"</span>");
			
		}//if year has value
		
	};
		
 $.fn.anniversaryPicker.defaults = {
		 dropdown: "#yearVal",
		 giftType: "giftType",
		 formArea: "#formArea",
		 txtArea: "#txt"
  };//defaults
	
})(jQuery);
