var brands = {
	img     : null,	
	timeout : null,	
	lastPosition : 0,
    toogle : function(id){
    	if (id == '#brands'){
    		if (brands.lastPosition == -brands.img.height + 92){
    			brands.lastPosition = 92;
    		}
    		brands.lastPosition -= 92;
    		$(id).stop().animate({opacity : 0}, {duration : 500, complete : function(){
        		$(this).css({backgroundPosition : "0px " + (brands.lastPosition).toString() + "px"});
        		$(this).animate({opacity : 1},{duration : 500});
        		
        	}});
    	}else if (id == '#the-brands'){
    		if (brands.lastPosition == brands.img.width - 100){
    			brands.lastPosition = -100;
    		}
    		brands.lastPosition += 100;
    		$(id).stop().animate({opacity : 0}, {duration : 500, complete : function(){
        		$(this).css({backgroundPosition : (brands.lastPosition).toString() + "px" + " 0px"});
        		$(this).animate({opacity : 1},{duration : 500});
        		
        	}});
    	}
    	
    	clearTimeout(brands.timeout);
    	brands.timeout = setTimeout("brands.toogle('"+id+"')", 5500); 
    }
};
	
$(function(){
	
	$(".b64").each(function(i, el){
		$(el).html(base64_decode($(el).html()));
	});
	
	
        $('.eem').click(function(){
            a_mail = this;
            $("#mail-dialog").show();
			$("#mail-dialog").dialog('open');
            $('#mail-dialog').dialog({
                modal : true,
                height : 500, 
                width  : 400,
                overlay: { 
                    opacity: 0.5, 
                    background: "black" 
                },
                open : function(){
                    $.post(
                        $(a_mail).attr('href'),
                        {}, 
                        function(data, status){
                            $("#mail-dialog").html(data);
                        }, 
                        'text');
                },
                buttons : {
                    'Wyślij' : function(p1){
                        $(p1.target).html('<img src="public/gfx/ajax-loader-small.gif"/>&nbsp;&nbsp;Wysyłanie ...');
                        
                        data = {
                            personal : $('#mail-dialog #personal').val(),
                            company : $('#mail-dialog #company').val(),
                            phone : $('#mail-dialog #phone').val(),
                            email : $('#mail-dialog #email').val(),
                            msg : $('#mail-dialog #msg').val(),
                            reciver : $('#mail-dialog #reciver').val()
                        };
                        
                        //show overlay
                        $.post(
                            "mail/index/send",
                            data,
                            function(data, status){
                                if(data['response'] == 'success') {
                                    $(p1.target).html('Wyślij');
									$("#mail-dialog").dialog("close");
                                } else if (data['response'] == 'error' && data['form'] != undefined) {
                                    $(p1.target).html('Wyślij');
                                    $("#mail-dialog").html(data['form']);
                                } else {
                                    alert('server error');
                                }
                            },
                            'json'
                        );
                    }
                }
            });
            return false;
        });
     
    brands.img = new Image();     
    if ($('#brands').length){
    	brands.img.src = e4BaseUrl + 'public/gfx/logos-horizontal.jpg';
    	brands.img.onload = function(){
    		brands.timeout = setTimeout("brands.toogle('#brands')", 5000);
    	}
    }else if ($('#the-brands').length){
    	brands.img.src = e4BaseUrl + 'public/gfx/logos-vertical.jpg';
    	brands.img.onload = function(){
    		brands.timeout = setTimeout("brands.toogle('#the-brands')", 5000);
    	}
    }
});



        
