$(document).ready(function() {
	$('.diler_link .link').click(function() {
    $('.diler_cont').toggle();
	});
	
	$('.search_new b').click(function() {
    $('.text_box').toggle();
	});
	
	$(".header .top_menu li:first").addClass("first");
	$(".footer .footer_menu  li:first").addClass("first");
});

$(document).ready(function() {

	//rotation speed and timer
	
	//grab the width and calculate left value
	var item_width = $('#slides li').outerWidth(); 
	var left_value = item_width * (-1); 
        
    //move the last item before first item, just in case user click prev button
	$('#slides li:first').before($('#slides li:last'));
	
	//set the default item to the correct position 
	$('#slides ul').css({'left' : left_value});

    //if user clicked on prev button
	$('#prev').click(function() {

		//get the right position            
		var left_indent = parseInt($('#slides ul').css('left')) + item_width;

		//slide the item            
		$('#slides ul:not(:animated)').animate({'left' : left_indent}, 200,function(){    

            //move the last item and put it as first item            	
			$('#slides li:first').before($('#slides li:last'));           

			//set the default item to correct position
			$('#slides ul').css({'left' : left_value});
		
		});

		//cancel the link behavior            
		return false;
            
	});

 
    //if user clicked on next button
	$('#next').click(function() {
		
		//get the right position
		var left_indent = parseInt($('#slides ul').css('left')) - item_width;
		
		//slide the item
		$('#slides ul:not(:animated)').animate({'left' : left_indent}, 200, function () {
            
            //move the first item and put it as last item
			$('#slides li:last').after($('#slides li:first'));                 	
			
			//set the default item to correct position
			$('#slides ul').css({'left' : left_value});
		
		});
		         
		//cancel the link behavior
		return false;
		
	});        
	
	//if mouse hover, pause the auto rotation, otherwise rotate it


        $(document).keyboard('ctrl+enter', sendmsg);

    $(".open_er").click(function(){
        $(".send_error_message").css('display','none');
    })

    function sendmsg(){
        if(window.getSelection)
            txt = window.getSelection().toString();
        else if(document.getSelection)
             txt = document.getSelection();
         else if(document.selection)
             txt = document.selection.createRange().text;


        var popupY = $(document).scrollTop() + Math.round($(window).height()/2) - Math.round($(".send_error_message").height()/2);

        $(".send_error_message").css('top', popupY);
        $(".send_error_message").css('display','block');
            locat = document.location;
        $("#selected_text").text('<!!!>'+txt+'<!!!>');
        $("#selected_url").text('url: '+locat);
        $("#textarea").html('<textarea rows="5" cols="" id="comment_selected" name="comment_selected" style="border: 1px solid #C5B895; width: 220px;"></textarea>');

        //alert(document.location);
    }
     $("#er_button").click(function(){
        var error = $("#selected_text").text();
        var url = document.location+'';
        var comment = $('#comment_selected').val();
//alert(error);
//alert(url);
//alert(comment);
        $.get("/kontakty", { act: 'error', error: error, url: url, comment:comment},
               function(data){

                 if(data=='ok'){
                     $(".send_error_message").css('display','none');
                 }
        });

     })




        
});

//a simple function to click next link
//a timer will call this function, and the rotation will begin :)  
function rotate() {
	$('#next').click();
}
        
        
        
