/*************************************************************************/
/*                                                                       */
/*    project:  LITTLE web 2009                                          */
/*    code:     little_script.js                                         */
/*    author:   Radovan Čapek                                            */
/*    date:     21.8.2009                                                */
/*                                                                       */
/*************************************************************************/
var default_x = 555;
var default_y = 480;
/********************************************************************/
/*     HomePage scripts                                             */
/*     requirements : jQuery.js                                     */
/********************************************************************/
$(document).ready(
/********************************************************************/
/*     HomePage scripts                                             */
/*     requirements : jQuery.js                                     */
/********************************************************************/
    function () {
 
        $('#gray_box a, #pink_box a').bind(
    		'click',	
              openAJAXwindow
          );
        $('.openWindow a').bind(
    		'click',	
              openAJAXwindow
          );
        $('#li_close').bind(
    			'click',
    			function()
    			{
    				$('#fade').css('display', 'none');
            $('#little_info').hide();
    			}
    		);
        var productWidth;		
        $('div.sliderGallery').each(function () {
              var ul = $('ul', this);
              productWidth = ul.innerWidth() - $(this).outerWidth();
          
          });
        
        $('#shift_right').bind(
          'mouseover',
          	function()
          	{
                $('.sliderGallery ul').animate({'left': '-' + productWidth+ 'px'}, 2500, 'linear');
          	}
        );
        $('#shift_left').bind(
          'mouseover',
          	function()
          	{
                $('.sliderGallery ul').animate({'left': '0px'}, 2500, 'linear');
          	}
        );
          $('#shift_right,#shift_left').bind(
          'mouseout',
          	function()
          	{
                $('.sliderGallery ul').stop();
          	}
        );
        
        $('.sliderGallery a').bind(
            'click',
            function(e) {
            
                e.preventDefault();
                var src = $("img", this).attr("src");
                var length = src.length;
                src = src.substr(0, length-9);
                srca = src + 'max=498';
                src = src + 'max=498';

                //alert(src);
                $("#destination_img").attr("src",src);
                $("#destination_a").attr("href",srca);
                /*
                $.ajax({ 
                          method: "get",
                          url: "http://svn.gad.cz/little2/web/getimage.php?",
                          data: "file=http://svn.gad.cz/little2/web/_data/user_files/hotels/4/7/47561/47561&width=500",
                          //beforeSend: function() { $("#li_content").html("<img src='../../web/_data/templates/little/img/loading.gif' alt='loading...' class='loading' />") },
                          success: function(html) { //so, if data is retrieved, store it in html 
                              $(this).html(html);
                              alert(html);
                          } 
                }); //close $.ajax
                */
            }
        );

/********************************************************************/
/*     end of JQUERY.document.ready                                 */
/********************************************************************/			
    }
);



/********************************************************************/
/*     script name: open AJAX window                                */
/*     describe: open/close the lightbox AJAX window                */
/********************************************************************/

var openAJAXwindow = function(e)
{
      e.preventDefault();
    	
    	if( $(this)[0].getAttribute('winsize') != null ) {
      
            var winsize = $(this)[0].getAttribute('winsize');
            var sizes = new Array();
            sizes = winsize.split("x");
            //alert(sizes.toString());
            $('#little_info').css("width",sizes[0]+"px");
            $('#little_info').css("height",sizes[1]+"px"); 
      }
      else {
           $('#little_info').css("width",default_x+"px");
           //$('#little_info').css("height",default_y+"px");
           $('#little_info').css("height",default_y+"px"); 
      }
      
      $('#iframe').css("width","500px");
      //$('#little_info iframe').css("height",sizes[1]+"px"); 
       	    	   
    	//var topPosition = $(window).scrollTop() + $(window).height()/2 - parseInt($("#little_info").height()/2);
    	var topPosition = $(window).scrollTop() + $(window).height()/2 - 500/2;
    	var leftPosition = ($(window).width()-parseInt($("#little_info").width()))/2 + 10;
    	if(leftPosition < 0) leftPosition = 0;
      $('#little_info').css('left', leftPosition+'px');
      $('#little_info').css('top', topPosition+'px');
          
      $('#fade').css('display', 'block');
    	if($('#little_info').css('display') == 'none') {
      	
      			$('#little_info').show(); 
    	}
    	
    	var link      = $(this)[0].getAttribute('href');
      //var type      = $(this)[0].getAttribute('type');
      var href      = $(this)[0].getAttribute('href');
      var js_domain = location.host;
      var js_path   = location.pathname;
      
      /*
      if(link.indexOf("?") != -1 ) {
      
            //ajax_data = link.substring(link.indexOf("?"));
            link      = link.substring(1, link.indexOf("?"));
      }
      */
      var frame = '<IFRAME src="'+link+'" scrolling="auto" style="width:'+ (parseInt($("#little_info").width()) -22) +'px;height:'+ (parseInt($("#little_info").height()) -35) +'px;"></IFRAME>';
    	$('#li_content').html(frame);
      /*
      $.ajax({ 
                method: "get",
                //url: "http://"+js_domain+"/little2/web/_data/templates/little/ajax.php",
                url: link,
                //data: "type="+type,
                beforeSend: function() { $("#li_content").html("<img src='../../web/_data/templates/little/img/loading.gif' alt='loading...' class='loading' />") },
                success: function(html) { //so, if data is retrieved, store it in html 
                    $("#li_content").html("<iframe>"+html+"</iframe>");
                } 
      }); //close $.ajax
      */
      this.blur();
      
};