// JavaScript Document
/* autor: DCWS Dawid Mazurek
	ImgBoxGallery ver 1.0
	e-mail: dcws@dcws.pl
	website: www.dcws.pl
*/
 $(document).ready(function(){  
	var $open = $('<img/>')
   .addClass('enlarged')
   .hide()
   .appendTo('body');
   if ($(window).height() < $('body').height()){
   	height_body = $('body').height();
   } else{
   	height_body = $(window).height();
   }
   var $bg = $('<div>')
   .addClass('bg_gallery')
   .css({
   'height' : height_body,
   'opacity': 0.6
   })
   .hide()
   .appendTo('body');
   
	function createControl(src) {
      return $('<img/>')
      .attr('src', src)
      .addClass('control')
      //.css('opacity', 0.6)
      .css('display', 'none');
   }
	var $closeButton = createControl('images/close1.gif')
   .addClass('enlarged-control')
   .appendTo('body');
	
	   $('a.item').addClass('hid');
		$('.menuitem').hide();
 $("a.item").fadeTo("fast", 1); 
		$("a.item").hover(function(){ 
			$(this).fadeTo("fast", .5);}, 
				function(){$(this).fadeTo("slow", 1); 
										}); 
 
$('a.item').click(function(){
	var wyrazenie = /^[0-9a-z_.-\/]+\.[0-9a-z.-]{3,4}$/i
	var sciezka = $(this).attr('href');

	 if (wyrazenie.test(sciezka) == false){
		alert('Niepoprawne łącze');
		return false;
	} else{  
	  $size_width = $(this).width();
	  $size_height = $(this).height();
	  var startPos = $(this).offset();
         startPos.width = $size_width;
         startPos.height = $size_height;
	
	  $size_width_end = $(this).find('img#item').width();
	  $size_height_end = $(this).find('img#item').height();
      var endPos = {};
         endPos.width = $size_width_end ;
         endPos.height = $size_height_end ;
         endPos.top = ($(window).height() - endPos.width) / 2;
         endPos.left = ($(window).width() - endPos.width) / 2;
	 $open.attr('src', $(this).attr('href'))
	  .css(startPos)
	  .show();
	 $bg.show();
	
	 //$open.hide();
	
	 var performAnimation = function() {
		 $('body').css({'background-color' : '#666'});
            $open.animate(endPos, 'slow',
                  function() {
               $open.one('click', function() {
                  $closeButton.unbind('click').hide();
                 // $priceBadge.hide();
				 
                  $open.fadeOut();
               });
               $closeButton
               .css({
                  'left': endPos.left + endPos.width + 13,
                  'top' : endPos.top - 13
               })
               .show()
               .click(function() {
                  $open.click()
				  $bg.hide();
               });
               /*$priceBadge
               .css({
                  'right': endPos.left,
                  'top' : endPos.top
               })
               .text(price)
               .show();*/
            });
	 };
		if ($open[0].complete) {
            performAnimation();
         }
         else {
            $open.bind('load', performAnimation);
         }
	 return false;
       //  event.preventDefault();
      
     // .hover(function() {
       //  $enlargeRollover.appendTo(this).show();
      //}, function() {
        // $enlargeRollover.hide();
      //});
	}
	});
   //.css({'width':'100', 'height':'70', 'overflow':'hidden'}); //Set all menu items to smaller size  
    /* $('img#item').click(function() { //When mouse over menu item  
	 	//$(this).removeClass('hid');
		//$(this).find('img').addClass('menuitem');
	var startPos = $('img#item').offset();
         startPos.width = $(this).width();
         startPos.height = $(this).height();
         var endPos = {};
         endPos.width = startPos.width * 3;
         endPos.height = startPos.height * 3;
         endPos.top = 100;
         endPos.left = ($('body').width() - endPos.width) / 2;
		
			$open.attr('src', $(this).attr('href')).css(startPos)
			var performAnimation = function() {
            $open.animate(endPos, 'normal',
                  function() {
               $open.one('click', function() {
                  //$closeButton.unbind('click').hide();
                  //$priceBadge.hide();
                  $open.fadeOut();
               }); 
			   $closeButton
               .css({
                  'left': endPos.left,
                  'top' : endPos.top
               })
               .show()
               .click(function() {
                  $open.click();
               });
               $priceBadge
               .css({
                  'right': endPos.left,
                  'top' : endPos.top
               })
               .text(price)
               .show();
            });
         };
			//$(this).animate({ 'height':'222', 'width':'320', 'left':'-=70', 'top':'-=50'}, 500)
       //  .show();
			//$(this).removeClass('hid')
				//$(this).addClass('menuitem')
				//stop()
		//$(th//is).stop();
   //      gridimage = $(this).find('img').addClass('menuitem'); //Define target as a variable  
     //    gridimage.stop().animate({width: 300, opacity: 0.25}, 500, function() {  $(this).animate({opacity: 1});}) //Animate image expanding to original size  
//  		gridimage.stop().animate({width: 300, opacity: 0.25}, 500, function() {  $(this).animate({opacity: 1});})
  
     });
	 $('.item').mouseout(function(){ //When mouse no longer over menu item  
	 //$(this).addClass('hid');
	// image = $(this).find('a')
	 //$(this).animate({ 'height':'100', 'width':'100', 'left':'+=70', 'top':'+=50'}, 500)
	 //$(this).addClass('hid')
	  //$(this).removeClass('menuitem')
	 //stop();
	  //$(this).stop();
	 //$('menu_1').animate({width: 250},0);
   		//$(this).find('img').removeClass('menuitem');
         //gridimage.stop().animate({width: 100, opacity: 0.25}, 500, function() {  $(this).animate({opacity: 1}, 150);
//  }); //Animate image back to smaller size  
  	 
    });  
  }); */


/*
// JavaScript Document
 $(document).ready(function(){  
   $('a#item').addClass('hid'); //Set all menu items to smaller size  
   
     $('a#item').mouseover(function() { //When mouse over menu item  
	 	$('a#item').removeClass('hid');
        // gridimage = $(this).find('img').addClass('menuitem'); //Define target as a variable  
         //gridimage.stop().animate({width: 300, opacity: 0.25}, 500, function() {  $(this).animate({opacity: 1});}) //Animate image expanding to original size  
//  		gridimage.stop().animate({width: 300, opacity: 0.25}, 500, function() {  $(this).animate({opacity: 1});})
  
     }).mouseout(function(){ //When mouse no longer over menu item  
   		$(this).find('img').removeClass('menuitem');
       //  gridimage.stop().animate({ opacity: 0.25}, 500, function() {  $(this).animate({opacity: 1}, 150);
//  }); //Animate image back to smaller size  
   
     });  */
 }); 
