
function showHideDiv(divId) {
	$('#'+divId).animate(
		{"height": "toggle"}, 
		{duration: 400}
	);
}
// Function for adding textFields in create and update forms
function add() {
	 
    //Create an input type dynamically.
    var element = document.createElement("input");
    var element1 = document.createElement("input");
   
    //Assign different attributes to the element.

    element.setAttribute("name", "poll_answer[]");
    element.setAttribute("type", "text"); 

 //   element1.setAttribute("name", "answers[]");
   // element1.setAttribute("type", "radio");
    //element1.setAttribute("value", "radio"); 
    var foo = document.getElementById("fooBar");
    
    //Append the element in page (in span).
    //foo.appendChild(element1);
    foo.appendChild(element);
}

function showAlert(){
var alert=('Kur'); 
}

// Slideshow
function slideSwitch() {
    var $active = $('#slideshow A.active'); // IMG
    
    if($active.length == 0)
    {
    	$active = $('#slideshow A:last'); // IMG
    }

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next() : $('#slideshow A:first'); // IMG

    // uncomment the 3 lines below to pull the images in random order
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() {
    	$active.removeClass('active last-active');
    });
}

function setCategory(categoryId)
{
	$('#parent').val(categoryId);
	
	$('a.a_link_red').removeClass();
	$('a.a_link_red').addClass('a_link_green');
	
	var a_category = $('#a_cat-'+categoryId);
	a_category.removeClass();
	a_category.addClass('a_link_red');
}

function getCategoryDetails(categoryId, categoryName)
{
	setCategory(categoryId);
	
	$('#tree_details').css('color', 'blue');
	$('#tree_details').css('font-style', 'normal');
	$('#tree_details').css('font-weight', 'bold');
	$('#tree_details').html(categoryName);
	
	$('#cat_edit_link').css('display', 'block');
	$('#cat_delete_link').css('display', 'block');
	
	$('#cat_edit_link').attr('href', 'index.php?r=category/create&categoryId='+categoryId);
	$('#cat_delete_link').attr('href', 'index.php?r=category/delete&categoryId='+categoryId);
//	$('#cat_delete_link').attr('onClick', "deleteCategory(" + categoryId + ", '" + categoryName+ "')");
}

function deleteCategory(categoryId, categoryName)
{
	var dialogResult = window.confirm('Сигурни ли сте, че искате да изтриете категория: ' + categoryName + '?');
	if(dialogResult)
	{
		window.location = 'index.php?r=category/index&categoryId='+categoryId;
	}
}

//$(document).ready(function() {
//    //Execute the slideShow
//    slideShow();
//});
 
function slideShow() {
    //Set the opacity of all images to 0
    $('#gallery a').css({opacity: 0.0});
     
    //Get the first image and display it (set it to full opacity)
    $('#gallery a:first').css({opacity: 1.0});
     
    //Set the caption background to semi-transparent
    $('#gallery .caption').css({opacity: 1.0}); // Tova beshe 0.7
 
    //Resize the width of the caption according to the image width
    $('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
     
    //Get the caption of the first image from REL attribute and display it
    if($('#gallery .content').html($('#gallery a:first').find('img').attr('rel')))
    {
    	$('#gallery .content').html($('#gallery a:first').find('img').attr('rel')).animate({opacity: 1.0}, 400); // Tova beshe 0.7
    }
     
    //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
    setInterval('gallery()',6000);
}
function slideShowOneElement() {
    //Set the opacity of all images to 0
    $('#gallery a').css({opacity: 0.0});
     
    //Get the first image and display it (set it to full opacity)
    $('#gallery a:first').css({opacity: 1.0});
     
    //Set the caption background to semi-transparent
    $('#gallery .caption').css({opacity: 1.0}); // Tova beshe 0.7
 
    //Resize the width of the caption according to the image width
    $('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
     
    //Get the caption of the first image from REL attribute and display it
    if($('#gallery .content').html($('#gallery a:first').find('img').attr('rel')))
    {
    	$('#gallery .content').html($('#gallery a:first').find('img').attr('rel')).animate({opacity: 1.0}, 400); // Tova beshe 0.7
    }
     
    //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
    //setInterval('gallery()',6000);
}
 
function gallery() {
    //if no IMGs have the show class, grab the first image
    var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));
 
    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));   
     
    //Get next image caption
    var caption = next.find('img').attr('rel'); 
     
    //Set the fade in effect for the next image, show class has higher z-index
    next.css({opacity: 0.0})
    .addClass('show')
    .animate({opacity: 1.0}, 1000);
 
    //Hide the current image
    current.animate({opacity: 0.0}, 1000)
    .removeClass('show');
     
    //Set the opacity to 0 and height to 1px
    $('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 }); 
     
    //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
    $('#gallery .caption').animate({opacity: 1.0},100 ).animate({height: '150px'},500 ); // Tova beshe 0.7
     
    //Display the content
    $('#gallery .content').html(caption);        
}
