// ****
// Initialize the Popup Windows
// ****
jQuery(document).ready(function(){
   jQuery("#calcResults").buildContainers({
      containment:"document",
      elementsPath:"/wp-content/elements/"
   });
   //jQuery("#calcResults").mb_toggle();
   jQuery("body").append(jQuery("#calcResults"));
});

function getAttacks() {
   var result = "";
   jQuery("#tweakWeaponSectionContent>div div").each(function(i) {
      value = jQuery(this).slider('option', 'value');
      if (result != "") {
         result = result + "~";
      }
      result = result + value;
   });
   return result;
}

function getHitzones() {
   var result = "";
   jQuery("#tweakHZSectionContent>div div").each(function(i) {
      value = jQuery(this).slider('option', 'value');
      if (result != "") {
         result = result + "~";
      }
      result = result + value;
   });
   return result;
}

function calculate() {
   containerShow(jQuery("#calcResults"));
   loadFelyne("#calcResults .content");
   var implodedAttacks = getAttacks();
   var implodedHZs = getHitzones();
   var switches =
      jQuery("input[name='sharpness']:checked").val() + "~" +
      jQuery("input[name='adrenaline']:checked").val() + "~" +
      jQuery("input[name='eleatck']:checked").val() + "~" +
      jQuery("input[name='heroics']:checked").val() + "~" +
      jQuery("input[name='aou']:checked").val() + "~" +
      jQuery("input[name='keep']:checked").val() + "~" +
      jQuery("#reckless").val() + "~" +
      jQuery("#attackup").val() + "~" + 
      jQuery("input[name='pwr']:checked").val() + "~" +
      jQuery("input[name='kitatup']:checked").val() ;

   var ids = { langkey: getGlobalLangKey(),
      attacks : implodedAttacks,
      hitzones: implodedHZs,
      hlevel: jQuery("#hunterLevel").val(),
      qlevel: jQuery("#questLevel").val(),
      switches: switches,
      weapon: jQuery("#weaponClass").val(),
      monsterID: jQuery("#monsterSelect").val(),
      type: "calculate" };

	jQuery.ajax({
		type: "post",
		url: "http://www.reign-of-the-rathalos.com/wp-content/weaponCalcTools.php",
		data: ids,
		success: function(html) {
         containerShow(jQuery("#calcResults"));
         jQuery("#calcResults .content").html(html);
         jQuery("#wcacc").accordion({
			   autoHeight: false
		   });
      }
	});

}

function slideIt() {
   jQuery('#mainSection').click(function() {
		jQuery('#mainSectionContent').toggle('slow');
		return false;
	});
	jQuery('#maintab1').tabs();

   jQuery('#skillSection').click(function() {
		jQuery('#skillSectionContent').toggle('slow');
		return false;
	});
	jQuery('#maintab2').tabs();

	jQuery('#tweakWeaponSectionContent').hide();
   jQuery('#tweakWeaponSection').click(function() {
		jQuery('#tweakWeaponSectionContent').toggle('slow');
		return false;
	});
	jQuery('#maintab3').tabs();
	jQuery('#tweakHZSectionContent').hide();
   jQuery('#tweakHZSection').click(function() {
		jQuery('#tweakHZSectionContent').toggle('slow');
		return false;
	});
	jQuery('#maintab4').tabs();

}

function createMonsterList(idtag) {
   var ids = { langkey: getGlobalLangKey(), type: "monsterSelect" };
   loadFelyne(idtag);

	jQuery.ajax({
		type: "post",
		url: "http://www.reign-of-the-rathalos.com/wp-content/weaponCalcTools.php",
		data: ids,
		success: function(html) {
		   jQuery(idtag).html(html);
		   jQuery('#monsterSelect').change(function() {
		      createHitZones("#tweakHZSectionContent");
		   });
		   createHitZones("#tweakHZSectionContent");
		}
	});
}

function createAttacks(idtag) {
   var ids = { langkey: getGlobalLangKey(),
      type: "attacks",
      weapon: jQuery("#weaponClass").val()};
   loadFelyne(idtag);

	jQuery.ajax({
		type: "post",
		url: "http://www.reign-of-the-rathalos.com/wp-content/weaponCalcTools.php",
		data: ids,
		success: function(html) {
		   jQuery(idtag).html(html);
		   jQuery("#tweakWeaponSectionContent>div div").each(function(i) {
		      value = jQuery(this).html();
		      jQuery(this).html("");
		      jQuery(this).slider({min: 0, max: 10, value: value});
		   });
		}
	});
}

function createHitZones(idtag) {
   var ids = { langkey: getGlobalLangKey(),
      type: "hitZones",
      monsterID: jQuery("#monsterSelect").val(),
      weapon: jQuery("#weaponClass").val()};
   loadFelyne(idtag);

	jQuery.ajax({
		type: "post",
		url: "http://www.reign-of-the-rathalos.com/wp-content/weaponCalcTools.php",
		data: ids,
		success: function(html) {
		   jQuery(idtag).html(html);
		   jQuery("#tweakHZSectionContent>div div").each(function(i) {
		      value = jQuery(this).html();
		      jQuery(this).html("");
		      jQuery(this).slider({min: 0, max: 10, value: value});
		      jQuery("#calculate").attr("disabled", false);
		   });
		}
	});
}
