
function carouselItemChange(blogId, photoId){
	$("#comments-load").load("/blogdata/" + blogId +"-"+ photoId + "/", function(){
		$("#photo-description").html( $("#photo-perex").html() );
		$("#item_ident").val(photoId);
		$("#item_name").val( $("#photo-name").text() );
		//updateFlashColor();
	});

}
function carouselItemActiveClicked(blog_id, item_id, item_name, item_photo, item_url) {
	if(item_url) {
		window.open(item_url);
	} else {
		var parts = item_photo.split('/');
		tb_show('', '/image-cache/max-900x750/'+parts[parts.length-1]);
	}
} 

function updateFlashColor() {
	var col = $("html").css('backgroundColor');
		 col = col.substring(4);
	var rgb = col.split(",");
	var hex = "#" + RGBtoHex(parseInt(rgb[0]), parseInt(rgb[1]), parseInt(rgb[2]));

	document.getElementById("blogflash").setBackgroundColor(hex);
}
function RGBtoHex(R,G,B) {
	return toHex(R)+toHex(G)+toHex(B);
}
function toHex(N) {
 if (N==null) return "00";
 N=parseInt(N); if (N==0 || isNaN(N)) return "00";
 N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
 return "0123456789ABCDEF".charAt((N-N%16)/16)
      + "0123456789ABCDEF".charAt(N%16);
}

function GetMarginTopText(box1, box2, MasterDiv) {
    /* GetMarginTopText by Jiri Mudroch */
    var box1H = $('#' + box1).height();
    var box2H = $('#' + box2).height();
    if (MasterDiv == 1) {
      var Vysledek = Math.ceil((box1H - box2H)/2);
      if (Vysledek < 0) {
        $('#' + box1).css("margin-top", (-1)*Vysledek);
      }else{
        $('#' + box2).css("margin-top", Vysledek);
      }
    }else{
      var Vysledek = Math.ceil((box2H - box1H)/2);
      if (Vysledek < 0) {
        $('#' + box2).css("margin-top", (-1)*Vysledek);
      }else{
        $('#' + box1).css("margin-top", Vysledek);
      }
    }
}
/* check div exists -> fu*k Xstand. editor */
$(function(){

	$("#sendcomment").hide();
	$(".add-comment").click(function(){

		$("#sendcomment").toggle();
		return false;
		
	});

  if ($('#centertextindiv').length) {
    $(window).load(function() { 
      GetMarginTopText('JSbox1-left', 'JSbox1-right', 1);
      GetMarginTopText('JSbox2-left', 'JSbox2-right', 0);
      GetMarginTopText('JSbox3-left', 'JSbox3-right', 1);
      GetMarginTopText('JSbox4-left', 'JSbox4-right', 0);
      GetMarginTopText('JSbox5-left', 'JSbox5-right', 1);
      GetMarginTopText('JSbox6-left', 'JSbox6-right', 0);
    });
  }

// MENU BAR HEIGHT
  setMenubarHeight();

// SKIN SWITCH
  $('#apple-menu-bar li').click(function() {
      var date = new Date();
      var skin = $(this).attr("class");
      date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
      $.cookie("skin", skin, { path: '/', expires: date });
      $("html").removeClass().addClass(skin);
      $('#apple-menu-bar').pngFix();
      //updateFlashColor();
      //$('#apple-menu-bar li[class!='+skin+']').css("backgroundImage","none");
      return false;
  });
                
});
function theRotator() {

	//Set the opacity of all images to 0
	root.children('li').hide();
	
	//Get the first image and display it (gets set to full opacity)
	root.children('li:first').show().addClass('show');
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',3000);
	
}
 
function rotate() {	

	//Get the first image
	var current = (root.children('li.show')?  root.children('li.show') : root.children('li:first'));
 
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? root.children('li:first') :current.next()) : root.children('li:first'));
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.fadeOut(1000)
	.addClass('show')
	.fadeIn(1000);
 
	//Hide the current image
	current.fadeOut(1000)
	.removeClass('show');
	
};


$(function () {

  $(document).pngFix();

	if ($('#photo-cycl').length > 0) {
	  $('#photo-cycl ul').innerfade({ 
	  	timeout: 3000
	  });
	}

	/* blogs send form */  
	$('form#sendcomment').submit(function() {

	var data = null;
	var url = $('#urlsenddata').val();
	data = $('form#sendcomment').serialize();
	$('form#sendcomment input[type=submit]').attr('disabled', 'disabled').fadeTo(100,.5).val('Odesílám');

	$.ajax({
	type    : "POST",
	cache   : false,
	url     : url,
	data    : data + "&__event_onclick[sendcomment]=Přidat komentář",
	success: function(msg){

        var errors = $("#noticererr", msg).html();
		$('#noticererr').html(errors);

		if ($("#noticererr", msg).children('.ok').length == '1') {
			/* remove text */
			$('#user_name').attr('value', '');
			$('#text').attr('value', '');
		}
        
		return false;
	}
	});
	
	$('form#sendcomment input[type=submit]').removeAttr('disabled').fadeTo(100,1).val('Přidat komentář');;
	return false;
	
	});

});


function setMenubarHeight() {
	
	$("#apple-menu-bar").css("height", ( $("#apple-menu").height() + "px" ) );

}

