
function base64_decode( data ) {    // Decodes data encoded with MIME base64
 
 
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';
 
    do {  
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));
 
        bits = h1<<18 | h2<<12 | h3<<6 | h4;
 
        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;
 
        if (h3 == 64)      enc += String.fromCharCode(o1);
        else if (h4 == 64) enc += String.fromCharCode(o1, o2);
        else               enc += String.fromCharCode(o1, o2, o3);
    } while (i < data.length);
 
    return enc;
}

var FirstRun = 1;
var opacity1 = 0;
var opacity2 = 0;

var First_flag = 0;

$(document).ready(function(){
	checkEleHeight('.home_left_column_height');

  settings = {
          tl: { radius: 15 },
          tr: { radius: 15 },
          bl: { radius: 15 },
          br: { radius: 15 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }

  $('#top_image_block1_corner').each(function(){
	$(this).corner(settings);	
  });
  $('#top_image_block2_corner').each(function(){
	$('#top_image_block2_corner').corner(settings);	
  });
  
	$('#top_image_block2').each(function(){
		setTimeout("TimeChangeImage()",speed_one_cicle);
	});
	
	$("#select_rezepte_list").each(function(){
		ChangeRezepteList();
	});
	
});


function TimeChangeImage(){
	if(opacity1 == 100){
		if(FirstRun == 1){
			if(First_flag == 0){
				curent_index = curent_index+2;
				First_flag = 1;
			}else{
				curent_index = curent_index+1;
			}
			if(curent_index > max_index) curent_index = 0;
			jQuery("#top_image").attr('src','uploads/tx_edittopslide/'+image_mas[curent_index]);
			FirstRun = 2;
			opacity1 = 0;
			opacity2 = 0;			
		}else{
			curent_index = curent_index+1;
			if(curent_index > max_index) curent_index = 0;			
			jQuery("#top_image_new").attr('src','uploads/tx_edittopslide/'+image_mas[curent_index]);
			FirstRun = 1;
			opacity1 = 0;
			opacity2 = 0;					
		
		}
		setTimeout("TimeChangeImage()",speed_beetween_cicle);
		return;
	}
	opacity1 = opacity1 + 10;
	opacity2 = opacity2 + 0.10;
	if(opacity1 == 100){
		var opacity3 = 0;
		var opacity4 = 0;		
	}else{
		var opacity3 = 100 - opacity1;
		var opacity4 = 1 - opacity2;
	}
	if(FirstRun == 1){
		$('#top_image_block1').css('filter','alpha(opacity='+ opacity3 +')');
		$('#top_image_block1').css('-moz-opacity',opacity4);
		$('#top_image_block1').css('opacity',opacity4);
	
		$('#top_image_block2').css('filter','alpha(opacity='+ opacity1 +')');
		$('#top_image_block2').css('-moz-opacity',opacity2);
		$('#top_image_block2').css('opacity',opacity2);	
	}else{
		$('#top_image_block2').css('filter','alpha(opacity='+ opacity3 +')');
		$('#top_image_block2').css('-moz-opacity',opacity4);
		$('#top_image_block2').css('opacity',opacity4);
	
		$('#top_image_block1').css('filter','alpha(opacity='+ opacity1 +')');
		$('#top_image_block1').css('-moz-opacity',opacity2);
		$('#top_image_block1').css('opacity',opacity2);		
	}
	setTimeout("TimeChangeImage()",speed_one_cicle);
}

function checkEleHeight(elementsClass){

    var largestElementHeight = 0;
    var elementHeight = 0;
    $.each( $(elementsClass), function(i, n){
        var elementHeight = $(n).height();

        if(elementHeight >= largestElementHeight){
            largestElementHeight = $(n).height();
        }
    });

    $(elementsClass).css("height",largestElementHeight);
	
}

var req = null;

function onItemClicked(num)
{
	ViewMaskWindow();
	//get product info
			if(req){
				req.abort();
			}
 			req = jQuery.post(
			base64_decode(page_describe_url) + '&tx_editdv7product_pi1[ProductId]='+ num,
			{

			},
			function(data){
				$("#content_body").html(data);
				UnViewMaskWindow();

			});	

}

function ViewMaskWindow(){


		var obj = jQuery("#content_body");
		obj.css("background","#CCCCCC");
		obj.css("filter","alpha(opacity=65)");
		obj.css("-moz-opacity","0.65");
		obj.css("opacity","0.65");
		obj.css("margin-right","20px");
		obj.html("");
		obj.css("height","300px");
		
		var top = jQuery("#content_body").position().top+110;
		jQuery(".LoaderDiv").css("top",top);
		jQuery(".LoaderDiv").css("left",450);	
		jQuery(".LoaderDiv").css("display","block"); 	

}
  
function UnViewMaskWindow(){
	var obj = jQuery("#content_body");
	obj.css("background","none");
	obj.css("filter","alpha(opacity=100)");
	obj.css("-moz-opacity","1");
	obj.css("opacity","1");
	obj.css("height","auto");


	jQuery(".LoaderDiv").css("display","none");	
}  

var req_rezept = null;

function ChangeRezepteList(){
	var id_product = $("#select_rezepte_list").val();
	$("#list_rezepte").html('<div style="text-align:center;" width="100%"><img src="fileadmin/templates2/img/loading.gif" width="60px;"></div>');			
	
	if(req){
		req.abort();
	}
	
	req = jQuery.post(
		'/index.php?id='+ page_for_get_rezept + '&tx_editdv7rezepte_pi2[ProductId]='+ id_product+"&L="+rezept_lang,
		{
		},
		function(data){
			$("#list_rezepte").html(data);
		});		

}

