$(document).ready(function(){
	$("#variations input:radio").removeAttr("checked");

	$("#variations input:radio").each(function(index){
	    $(this).attr("id",index);
	});

	$("li.ui-tab a").each(function(index){
	    $(this).attr("rel",index);
	});

	$("li.ui-tab a").click(function(){
	    var index = $(this).attr("rel");
	    $('#variations input:radio[id=' + index + ']').attr("checked", "checked");
	});

});

$(document).ready(function(){
	var activeElement=null;
	$("#variations input:radio").each(function(index){
		$(this).click(function(){
			if(activeElement!=null){
				$(activeElement).addClass('ui-tabs-hide')
			}
			var element=$("#tabs-"+index);
			element.removeClass('ui-tabs-hide');
			activeElement=element;
			
		});
	});
	
});


/* added to external template in javascript in order to add translations */
function initializeDialog_org(titleText,actionUrl,thisPage){
$(document).ready(function(){
	$('#dialog').dialog('destroy');
	$('#dialog').dialog({
			autoOpen: false,
    		height: 200,
    		width: 350,
    		modal: true,
    		title: titleText,
    		closeText: 'Close',
    		buttons: {
					//OK
					'OK': function() {
						var formElement =$(this).find("form");
						$("#dialog input[name=ContentObjectID]").attr("value",$("#dialog input:checked").val());
						
						var data=formElement.serialize();
						$.post(actionUrl,data,
								function(){
									if($("div#shop").length){
										thisPage = document.location;
										$("#shop").load(thisPage +" #shop");
										//location.reload();
									}else{
										$("div.shopping-info").load(thisPage +" div.shopping-info div.action_box",
												function(){
														$("div.shopping-info").fadeOut(800).fadeIn(800).fadeOut(400).fadeIn(400).fadeOut(200).fadeIn(100);
												})
									}
								}
						);
						
						$(this).dialog('close');
					 }, 
					 //Cancel
					 'Cancel': function(){
						 $(this).dialog('close');
					 }
			},
			Cancel: function() {
				$(this).dialog('close');
			}
	});
	
	

	$('.product_variation_enabled').click(function(){
		var formParent=$(this).parents('form:first').parent();
		$('#dialog').html(formParent.html());
		$('#dialog').find(".productboxvitae").hide();
		$('#dialog').find(".options").show();
		$('#dialog').find(".product_variation_enabled").hide();
		$('#dialog').find(".end-button").hide();
		var dialog = $('#dialog');
		dialog.dialog('open');
		$("input:radio[id=" + $("input:radio:checked").attr('id') + "]").attr('checked', true);
		
			
		if(!$('#dialog input').is(':checked')){
				$("#dialog input:radio:first").attr('checked',true);
			}
	
		return false;
	});
	
	
  })
}//end function

/*
$(document).ready(function(){
	$('.product_variation_disabled').click(function(){
	
		var myelement=this;
		//alert($(myelement).parent().parent().attr('class'));
	
		var formElement = $(this).parents('form:first');
		var thisPage = document.location;
		var data=formElement.serialize();
		var actionURL = formElement.attr("action");
		$.post(actionURL,data,
			function(){
				if($("div.shopping-info").length){
					$("div.shopping-info").load(thisPage +" div.shopping-info div.action_box",
							function(){
								if($("div#shop").length){
									location.reload();
								}else{
									//alert($(myelement).parent().parent().attr('class'));
									$(myelement).parent().parent().fadeOut(800).fadeIn(800).fadeOut(400).fadeIn(400).fadeOut(200).fadeIn(100);
									
									$("div.shopping-info").addClass("orange_box");
									$("div.shopping-info").fadeOut(800).fadeIn(800).fadeOut(400).fadeIn(400).fadeOut(200).fadeIn(100, function(){
										$("div.shopping-info").removeClass("orange_box");
									});
								}
							});	
				}else{
					location.reload();
					//$("#shop").load(thisPage +" #shop",
						//	function(){
							//	if($("div#shop").length){
									//location.reload();
								//}else{
									//$("div.shopping-info").fadeOut(800).fadeIn(800).fadeOut(400).fadeIn(400).fadeOut(200).fadeIn(100);
								//}
							//});
				}
			
			
				
				});
	
		return false;
	});
});
*/

function parseXML(xml){
	$(xml).find("item").each(function()
			  {
				
			    $("div.shopping-info div.action_box strong.item_counter").append($(this).attr("count"));
			    $("div.shopping-info").show();
			    
			  });
	
}
