var carouselBefore = [];
var carouselAfter = [];
var minImgProperties = { width: 0, height: 0 };
var maxImgProperties = { width: 0, height: 0 };

$(document).ready(function()
{

    $("#carousel-clickmap-inner  .clickmap").click(function(){
      var clicked = $(this).attr('rel');
      var title = $("#carousel-content #carouselimage-" + clicked).attr('alt');
      var rel = $("#carousel-content #carouselimage-" + clicked).attr('rel');
      var link = $('span.link-' + rel).attr('rel');
      var src = $("#carousel-content #carouselimage-" + clicked).attr('src');

      if (jQuery.browser.msie) {
        var version = parseInt(jQuery.browser.version);
        if (version == 6) {
          document.location = link;
          return;
        }
      }
      $("#carouselimage-main").attr('rel', rel);
      $("a.carousel-detail").attr('href', link);
      $("a.carousel-detail  img").fadeOut(500, function() {
        $("a.carousel-detail  img").attr('src', src);
        $("a.carousel-detail  img").fadeIn('fast');
        $(".carousel-navi-center strong").html(title);
        $(".carousel-navi-center a").attr('href', link);
      });
  }); 

/*
    //default styles
    if( $.fn.qtip && $.fn.qtip.styles )
    {
        $.fn.qtip.styles.iprima = { // Last part is the name of the style
            border: {
                width:2,
                radius:5,
                color:'#000000'
            },
            width:289,
            padding:0,
            background: '#000000',
            textAlign:'left',
            tip: {
                corner: 'bottomLeft',
                size: {
                    x:5,
                    y:5
                }
            }
        }
    }
 */
    
    /* Expand Panel */
    $(".open").click(function(){
                $("div#panel").slideDown("slow");   
                return false;
                }); 
    $(".top-title").click(function(){
                $("div#panel").slideDown("slow");   
                $("#toggle a").toggle();
                return false;
                }); 


    /* Collapse Panel */
    $(".close").click(function(){
                $("div#panel").slideUp("slow"); 
                });     

    /* Switch buttons from "Log In | Register" to "Close Panel" on click */
    $("#toggle a").click(function () {
                $("#toggle a").toggle();
                });


    /* Pasted from jsuchy.js */
    // Add to any link, Print
    $('.node-links .addtoany .a2a_dd').html('<span class="share"><span class="icon icon-share-17x24"></span>sdílet</span>');
    $('#a2apage_EMAIL').css('display', 'none');
    $('#a2apage_amazon_wish_list').css('display', 'none');
    $('.prima_print a').click(function() {
      window.print();
      return false;
      });


    // Form errors
    var shown = 0;
    $('.login-box #user-login .error').each(function() {
      if (shown == 0) { shown = 1; $("div#panel").slideDown("slow"); $("#toggle a").toggle(); }
      });
    $('.register-box #user-register .error').each(function() {
      if (shown == 0) { shown = 1; $("div#panel").slideDown("slow"); $("#toggle a").toggle(); }
      });

    // Set widthxheight of videoarchive.
    $('.greybox').each(function() {
        $(this).attr('rel', '978x565');
      });
    if (jQuery.browser.msie) {
      var version = parseInt(jQuery.browser.version);
      if (version == 6) {
        $('.greybox').each(function() {
            $(this).unbind('click');
            $(this).removeClass('greybox');
        });
      }
    }

	if( $(".carousel-profiles .jCarouselLite").length )
	{
		$(".carousel-profiles .jCarouselLite").jCarouselLite({
		    btnNext: ".carousel-profiles .next",
		    btnPrev: ".carousel-profiles .prev",
		    mouseWheel: true,
		    circular: false,
		    visible: 3,
		    start:1,
		    beforeStart: function(a) {
		  		$.each( a, function(i, o){
		  			var j = i+1;
					carouselBefore[j] = searchPropertiesImgByLi(a[i],j);
					if( j==1 && minImgProperties.width == 0 ) {
						minImgProperties.width = carouselBefore[j].width;
						minImgProperties.height = carouselBefore[j].height;
					}
					if( j==2 && maxImgProperties.width == 0 ) {
						maxImgProperties.width = carouselBefore[j].width;
						maxImgProperties.height = carouselBefore[j].height;
					}
				});
		    },
		    afterEnd: function(a) {
		  		$.each( a, function(i, o){
		  			var j = i+1;
					carouselAfter[j] = searchPropertiesImgByLi(a[i],j);
				});
			/*
		        alert(
					'before:\n'+
					'   1:'+carouselBefore[1].id+'\n'+
					'   2:'+carouselBefore[2].id+'\n'+
					'   3:'+carouselBefore[3].id+'\n'+
					'after:\n'+
					'   1:'+carouselAfter[1].id+'\n'+
					'   2:'+carouselAfter[2].id+'\n'+
					'   3:'+carouselAfter[3].id+'\n'
				);
				*/
				setImgNewProperties(carouselAfter[1].id, minImgProperties);
				setImgNewProperties(carouselAfter[2].id, maxImgProperties);
				setImgNewProperties(carouselAfter[3].id, minImgProperties);	
		    }
		});
	}
	
	if ($('div').hasClass('tabs')) {
    	$(".video-reference-container .fivestar-widget .fivestar-processed .form-item .description .user-rating").css("display", "none");
			$(".video-reference-container .fivestar-widget .fivestar-processed .form-item .description").css("display", "block");
  }

});

function searchPropertiesImgByLi(o,i) {
  	var item = { id: null, width: null, height: null };
    var li = $('#'+$(o).attr( 'id' ));
    var img = $('img',li);
    item.id = $(img).attr( 'id' );
    item.width = $(img).attr( 'width' );
    item.height = $(img).attr( 'height' );
	/*
    alert(
		'item:\n'+
		'   id:'+item.id+'\n'+
		'   width:'+item.width+'\n'+
		'   height:'+item.height+'\n\n'+
		'   minImgProperties.width:'+minImgProperties.width+'\n'+
		'   minImgProperties.height:'+minImgProperties.height+'\n'+
		'   maxImgProperties.width:'+maxImgProperties.width+'\n'+
		'   maxImgProperties.height:'+maxImgProperties.height+'\n'
	);
	*/
	return item;
}
function setImgNewProperties(imgId,property) {
    var img = $('#'+imgId);
	$(img).animate({ 
	        width: property.width+'px',
	        height: property.height+'px'
	      }, 200 );
	return img;
}

