// JavaScript Document

  $(document).ready(function(){

        $('.add_wishlist_anchors').each(function(){

           $(this).click(function(e){
              return addToWishList($(this).attr('title'), e.pageX , e.pageY);
           }); 

        });

  
          $('#a_get_emails').bind(
      			'click',
            function()
      			{
              //
              return false;
      			}
      		);
  });

  
  function addToWishList(products_id, x, y){
            $('#wishlist_dropper').html('');
            $('#wishlist_dropper').removeClass('wishlist_class');  
            $('#wishlist_dropper').addClass('loadable-element');  
            $('#wishlist_dropper').hide();
            $('#wishlist_dropper').stopTime("hide");
              
            
//            var theLeft = (x + 10) + 'px';
//            var theTop = (y - $('#wishlist_dropper').height()) + 'px';

            if(x && y){
            var theLeft = (x - ($('#wishlist_dropper').width() / 2)) + 'px';
            var theTop = (y - ($('#wishlist_dropper').height()/2)) + 'px';
            }else{
            var theLeft = (($('#a_add_to_wishlist_'+products_id).offset().left + ($('#a_add_to_wishlist_'+products_id).width()/2) ) - ($('#wishlist_dropper').width() / 2)) + 'px';
            var theTop = (($('#a_add_to_wishlist_'+products_id).offset().top + ($('#a_add_to_wishlist_'+products_id).height()/2) ) - ($('#wishlist_dropper').height()/2)) + 'px';
            }

     
            $('#centerScreen').css('left', theLeft);
            $('#centerScreen').css('top', theTop);
            $('#centerScreen').css('width', $('#wishlist_dropper').css('width'));
            $('#centerScreen').css('height', $('#wishlist_dropper').css('height'));
            

            $('#wishlist_dropper').css('left', theLeft);
            $('#wishlist_dropper').css('top', theTop);
            
            $('#centerScreen').show();

					$('#a_add_to_wishlist_'+products_id).effect(
					  "transfer",
						{
							to:'#centerScreen',
							className:'transferer3'
						},
						400,
						 function(){

              $('#wishlist_dropper').css('z-index',20);
              $('#wishlist_dropper').show();
              $('#centerScreen').hide();

                		$.ajax({
                		  type: "POST",
                      url: "/add_to_wishlist_app.php",
                      dataType: 'xml',
                      cache: false,
                      data: 'products_id='+products_id,
                      success: function(html){
                      
                      var ret = '';
                
                        $(html).find("response").each(function() {
                          var response = $(this);
                          $(response).find("status").each(function() {
                              //alert($(this).text());
                          });
                          var response = $(this);
                          $(response).find("info").each(function() {
                              ret = $(this).text();
                          });
                  
                        });
                        
                      $('#wishlist_dropper').removeClass('loadable-element');  
                      $('#wishlist_dropper').addClass('wishlist_class');  
                      $('#wishlist_dropper').html(ret);  
//****************
                        $('#wishlist_dropper').oneTime(3000, "hide", function() {
                          $('#wishlist_dropper').fadeOut(2000);
                          $('#wishlist_dropper').stopTime("hide");
                        });

                      $("#a_close_wishlist_dropper").click(function() {
                        //alert('xx');
                        $('#wishlist_dropper').stopTime("hide");
                        $('#wishlist_dropper').fadeOut(1000);
                        return false;
                      });

//******************

                      },
                      error: function(obj,aStatus,anError){
                	      $('#wishlist_dropper').text('HATA: ' + aStatus); 
                      }
                    });
                    
                  return false;

						}
            );	

    return false; 
  
  }

