$(document).ready(function(){

	if($(window).width() <= 1024) {
		$(".languagebox").addClass("smallscreen");
	}
	
	
	
	if (!jQuery.browser.msie || jQuery.browser.version != 6) {
		$(".selectedlanguagebox").hover(
			function() { 
				$(".languagedropdown").show(); 
			}, 
			function () {
		    $(".languagedropdown").hide(); 
	  	}
	  );
	}
  
  if (jQuery.browser.msie && jQuery.browser.version == 6) {
  	$(".selectedlanguage").toggle(
			function(e) { 
				e.preventDefault();
				$(".languagedropdown").show(); 
			},
			function(e) {
				e.preventDefault();
				$(".languagedropdown").hide(); 
			}
		);
  }
  
  //if (!jQuery.browser.msie || jQuery.browser.version != 6) {}
  
  $(".tree .exp > ul").show();
  
  $(".tree a.has").click(
  	function(e) {
  		e.preventDefault();
  		if($(this).hasClass("level1") && $(this).hasClass("current")) return;
  		if($(this).hasClass("level1"))
  		{
  			$(".tree .li_level1 > ul").hide();
  			$(".tree .li_level1 > a").removeClass("current");
  			$(this).addClass("current");
  		}
  		$(this).next().slideToggle(500);
  	}
  );
  
  $(".tree .level1").click(
  	function(e) {
  		e.preventDefault();
  		$(".tree .li_level1").removeClass("exp");
  		$(".tree .li_level1").children("a").removeClass("exp");
  		$(this).addClass("exp");
  		$(this).children("a").addClass("exp");
  	}
  );
  
  $("#newsrotator").rotator({ms:5000, n:1});
  $("#gbentryrotator").rotator({ms:10000, n:1, autoHeight:false });
});

function toggleUserInputFields(el) 
{
	if(el.attr("id") == "select_title1_input_INC")
	{
		$("#oxuser_company").show();
		$("#oxuser_vatid").show();
		$("#oxuser_fax").show();
	}
	else
	{
		$("#oxuser_company").hide();
		$("#oxuser_vatid").hide();
		$("#oxuser_fax").hide();
	}
}

function increaseAmount(id)
{	
	if(parseInt($(id+"").val()) >= 99)
	{
		return;
	}
	$(id+"").val(parseInt($(id+"").val())+1)
}

function decreaseAmount(id)
{
	if(parseInt($(id+"").val()) == 1)
	{
		return;
	}
	$(id+"").val(parseInt($(id+"").val())-1);
}

function submitForm(formId) {
	formId = "#" + formId;
	$(formId).submit();
}

function slideElementByCondition(slideElementId, slideConditionId, slideTime, callback) {
	slideElementId = "#" + slideElementId;
	slideConditionId = "#" + slideConditionId;
	if(slideTime == null || typeof slideTime == 'undefined')
	{
		slideTime = 800;
	}
	if($(slideConditionId).attr('value') == "1") { // opened at this point so close it
		if(callback == "reloadFormOnHideDelAddress")
		{
			$(slideElementId).slideUp(slideTime, function(){reloadFormOnHideDelAddress()});
		}
		else
		{
			$(slideElementId).slideUp(slideTime);
		}
	}
	else {
		$(slideElementId).slideDown(slideTime);
	}	
}

function showHideElementByCondition(slideElementId, slideConditionId) {
	slideElementId = "#" + slideElementId;
	slideConditionId = "#" + slideConditionId;
	if($(slideConditionId).attr('value') == "1") { // opened at this point so close it
		$(slideElementId).hide();
	}
	else {
		$(slideElementId).show();
	}	
}

function slideToggleElement(elementId, slideTime)
{
	if(slideTime == undefined) slideTime = 500; 
	elementId = "#" + elementId;
	$(elementId).slideToggle(slideTime);
}

function setOrderOption(id)
{
	id = "#" + id;
	if($(id).attr('value') == 1)
	{
		$(id).attr('value', '3');
	}
	else if($(id).attr('value') == 3)
	{
		$(id).attr('value', '1');
	}
}

function toggleBooleanInput(id)
{
	id = "#" + id;
	if($(id).attr('value') == 1)
	{
		$(id).attr('value', '0');
	}
	else if($(id).attr('value') == 0)
	{
		$(id).attr('value', '1');
	}
}

function setBooleanInputShowCompanyFieds(el)
{
	id = '#blshowcompanyfields';
	if(el.attr("id") == "select_title1_input_INC")
	{
		$(id).attr('value', '1');
	}
	else
	{
		$(id).attr('value', '0');
	}
}