$j = jQuery;

$j(document).ready( function() {
  
  $j(".ins_box",this).mouseover (function(){
    div_show($j(this),$j(".ins_box_contact",this));
  });
  
  $j(".ins_box",this).mouseout (function(){
    $j(".ins_box_contact",this).hide();
  });
  
  setTimeout("ro()",5000);
  
  $j('#przewodnicy').fadeTo(1,0.5);
  $j('#przewodnicy').bind({
  	click: function() { pr(); },
  	mouseenter: function() { $j(this).fadeTo(1000,1); },
    mouseleave: function() { $j(this).fadeTo(1000,0.5); }
	});
  
  
  
});



function div_show(trigger, div) {  
    var pos = $j(trigger).offset();    
    var eWidth = $j(trigger).outerWidth();
    var eHeight = $j(trigger).outerHeight();
    var mWidth = $j(div).outerWidth();
    //if ($j.browser.msie) var left = (pos.left - 238) + "px";
    //else
    var left = (pos.left - 35) + "px";
    var top = pos.top + eHeight - 85 + "px";
    
    $j(div).css({ 
      position: 'absolute',
      zIndex: 2,
      left: left, 
      top: top
    });
    $j(div).show();
};



function adv_show(trigger, div, mleft) {  
    var pos = $j(trigger).offset();
    var eWidth = 500;
    var eHeight = 300;
    
    var left = (pos.left - mleft) + "px";
    var top = pos.top - eHeight - 14 + "px";
    $j(div).css({
      position: 'absolute',
      zIndex: 2,
      left: left, 
      top: top
    });
    
    //$j(div).show();
    $j(div).fadeIn("slow");
};



function ro() {
  $j.ajax({
    url: "scripts/php/ro.php",
    type: "get",
    dataType: "xml",
    success: function(xml,textStatus){
      $j("images>image",xml).each( function(index){
        $j(".img_"+index).fadeTo("slow",0.6);
        $j(".img_"+index).fadeTo("slow",1);
        $j(".img_"+index).attr("src", "galeria/rotate/"+$j("name",this).text());
      })
    },
    error: function(XMLHttpRequest,textStatus,errorThrown){
      //alert("Problem retrieving data: " + textStatus);
    }
  });
  
  setTimeout("ro()",5000);
}

function pr() {
  $j.ajax({
    url: "scripts/php/pr.php",
    type: "get",
    dataType: "html",
    success: function(html,textStatus){
  	  $j('.hi').empty();
      $j(html).appendTo('.hi');
      $j('.hi').addClass("hiPrzewodnicy");
      
      var l = ($j('#przewodnicy').offset().left +200) + "px";
      var t = $j('#przewodnicy').offset().top - 260 + "px";
      
      $j('.hiPrzewodnicy').css({left: l, top: t});
      
      $j('.cl').bind({
      	click: function() { $j('.hi').removeClass("hiPrzewodnicy"); }
      });
    },
    error: function(XMLHttpRequest,textStatus,errorThrown){
      //alert("Problem retrieving data: " + textStatus);
    }
  });
}
