/******* Text Box Hints START ********/
		/**
		* @author Remy Sharp
		* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
		*/
		
		(function ($) {
			$.fn.hint = function (blurClass) {
			    if (!blurClass) blurClass = 'blur'; 	
			    return this.each(function () {
			        var $input = $(this),
			            title = $input.attr('title'),
			            $form = $(this.form),
			            $win = $(window);
			        function remove() {
			            if (this.value === title && $input.hasClass(blurClass)) {
			                $input.val('').removeClass(blurClass);
			            }
			        }
			        // only apply logic if the element has the attribute
			        if (title) { 
			            // on blur, set value to title attr if text is blank
			            $input.blur(function () {
			                if (this.value === '') {
			                    $input.val(title).addClass(blurClass);
			                }
			            }).focus(remove).blur(); // now change all inputs to title            
			            // clear the pre-defined text when form is submitted
			            $form.submit(remove);
			            $win.unload(remove); // handles Firefox's autocomplete
			        }
			    });
			};
		})(jQuery);
		
		$(function(){
			// elements with class 'blur'
			$('.blur').hint();
		});
/******* Text Box Hints END ********/

/******* Search City Home START ********/
		$(document).ready(function(){
			$('div#searchCity').hide(); // Hide searchCity block
			$('div#navWeather a.searchImg').click(function(){ //When link is clicked
				$('div#searchCity').toggle(); // Toggle searchCity block
				return false;
			});
		});
/******* Search City Home END ********/

/******* Weather Right Block START ********/
		$(document).ready(function(){
			$('a.searchImg').click(function(){ //When link (Избери град или Върни се обратно) is clicked
				var currentW = $('#searchCity'); // Set variable currentW to value of href attribute of clicked link				
				$(currentW).toggle();
				return false;			
			});
		});		
/******* Weather Right Block END ********/

/******* Sliding the Photo Gallery Caption & ThumbView START ********/
		$(document).ready(function() { 
			$('#view').click(function(){ //Changeing view on Click event
				if($(this).is('.singleView')){
					$('#photoSlideWrapper, #photoSlideNav, #photoSlideHoverCaption').show();
					$('#photoSlideThumbView, #photoSlidePagingNav, #photoSlideHoverThumb').hide();
					$('#view_toggle, #view_toggleThumb').removeClass('view_toggleUp');
					$('#toggle').removeClass('toggleUp');					
					$('#view, #viewThumb').removeClass('singleView');
				}else {
					$('#photoSlideWrapper, #photoSlideNav, #photoSlideHoverCaption').hide();
					$('#photoSlideThumbView, #photoSlidePagingNav, #photoSlideHoverThumb').show();
					$('#view_toggle').toggleClass('view_toggleUp');
					$('#toggle').addClass('toggleUp');
					$('#view').toggleClass('singleView');			        
			  	}
				return false;
			});
			$('#toggle, toggleThumb').click(function(){ // Sliding the Photo Gallery Caption on Click event
				$('#photoSlideHoverCaption, #photoSlideHoverCaptionThumb').slideToggle('slow', function(){
					$('#toggle, #toggleThumb').toggleClass('toggleUp');
				});	 		
				return false;
			});
		});
/******* Sliding the Photo Gallery Caption & ThumbView END ********/

/******* LAST PHOTO SLIDE START ********/
		$(function() {
			$('#photoSlide').cycle({ 
				fx: 'scrollLeft',
				speed: 'fast', 
				delay: 300,
				timeout: 0,
                                containerResize: true,
				next: '#photosNext',
				prev: '#photosPrev',
				pager: '#photoNav',
				pagerAnchorBuilder: function(idx, slide) { 
					// return selector string for existing anchor 
					return '#photoNav a:eq(' + idx + ')'; 
				}
			});
		});
/******* LAST PHOTO SLIDE END ********/

/******* Tabs START ********/
		$(document).ready(function(){
			$('div#lcmTabs div#lcmTabsInner > div').hide(); // Hide all divs
			$('div#lcmTabs div#lcmTabsInner > div:first').show(); // Show the first div
			$('div#lcmTabs div#lcmTabsInner ul li a:first').addClass('select'); // Set the class of the first link to active
			$('div#lcmTabs div#lcmTabsInner ul li a').click(function(){ //When any link is clicked
			$('div#lcmTabs').css('background-position', '297px 4px');
			$('div#lcmTabs div#lcmTabsInner ul li a').removeClass('select'); // Remove active class from all links
			$(this).addClass('select'); //Set clicked link class to active
			var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
			$('div#lcmTabs div#lcmTabsInner> div').hide(); // Hide all divs
			$(currentTab).show(); // Show div with id equal to variable currentTab
			return false;
			});
			$('div#lcmTabs div#lcmTabsInner ul li a:last').click(function(){
				$('div#lcmTabs').css('background-position', '297px 0');
			});
		});
		$(document).ready(function(){
                        $('div#aTabs div#phones, div#clothes, div#jewelry, div#auto, div#antiques').hide(); // Hide all divs
                        $('div#aTabs div.tabContentPromRow:first').show();
                        $('div#aTabs div.auctionCat a:first').addClass('select'); // Set the class of the first link to active
                        $('div#aTabs div.auctionCat a').click(function(){ //When any link is clicked
                        $('div#aTabs div.auctionCat a').removeClass('select'); // Remove active class from all links
                        $(this).addClass('select'); //Set clicked link class to active
                        var currentTab2 = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
                        $('div#aTabs div.tabContentPromRow').hide(); // Hide all divs
                        $(currentTab2).show(); // Show div with id equal to variable currentTab
                        return false;
                        });
		});
/******* Tabs END ********/

/******* SMOOTH SCROLLING START ********/		
$(document).ready(function(){
	$('#pTop a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html, body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});
});
/******* SMOOTH SCROLLING END ********/		

/******* PHOTO GALLERY FUNCTIONS ********/		
var oldAstro=1;
var oldThumbAstro=1;
var astro = 1;
var currentImage = 1;
var prevImage = 1;
var interval = 3500;
var slide = 0;
var picNum = 1;
var timerID = 0;
var picNumComment = 1;

$(document).ready(function() { 
			$('#pgPlay').click(function(){ // Changing the Play/Pause button on Click event
				$(this).toggleClass('pgPause');
				return false;
			});
			
			$('#pgpPlay').click(function(){ // Changing the Play/Pause button on Click event
				$(this).toggleClass('pgpPause');
				return false;
			});
		});

function showBigImg (picNum)
{
  //Hide/show the two versions of the photo gallery
  $('#photoSlideWrapper, #photoSlideNav, #photoSlideHoverCaption').show();
  $('#photoSlideThumbView, #photoSlidePagingNav, #photoSlideHoverThumb').hide();
  
  $('#view_toggle').removeClass('view_toggleUp');
  $('#view').removeClass('singleView');
  $('#toggle').removeClass('toggleUp');	
  
	ShowAstro(picNum);
}

/******* PHOTO GALLERY Version 1 START ********/
function nextImage()
{
  var maxImages = document.getElementById('maxImages').value;
  prevImage = currentImage;

  if(currentImage != maxImages) currentImage += 1;
  else { currentImage = 1;  picNum = 1; picNumComment = 1; }

  // Change pic
	$('#picture').attr({ src: 'image.php?path='+lastPhotos[currentImage]+'&resize=1' })
	
	// change Text
	$('#picText').html(lastPhotosTXT[currentImage]);
  
  document.getElementById('as'+currentImage).className = 'activeThumb';
  if(prevImage) document.getElementById('as'+prevImage).className = 'a';
  
  //Scroll controls to current element and get picture alt tag
	var LeftScroll = 65*currentImage-260;
	$('#photoSlideThumbNav').scrollLeft(LeftScroll);	
	oldAstroScroll = oldAstro = currentImage;
}

function slideOne() 
{
  var maxImages = document.getElementById('maxImages').value;
  
  if (picNum>=maxImages) //reset number in comment if max size is reached
  {
    picNum = picNumComment = 1;
    $('#picNum').html( picNum );
    $('#picNumComment').html( picNumComment );
  }
  else 
  {
    $('#picNum').html( ++picNum );
    $('#picNumComment').html( ++picNumComment );
  }	
  
  nextImage();
  timerID = setTimeout(slideOne, interval);
}

function slideImages(stop) 
{
  //If stop is set to 0, make slide=1 and stop scrolling
  if (stop == 0) 
  {
    slide = 1;
    $('#pgPlay').removeClass();
    $('#pgPlay').addClass('pgPlay');
  }
  
  if(slide == 0) {
    slide = 1;
    timerID = setTimeout(slideOne, interval);
  }
  else {
    slide = 0;
    clearTimeout(timerID);
    ShowAstro( oldAstro );
  }
}

function ShowAstro(astro) 
{
	// Select button	
	$('#as'+oldAstro).removeClass();
	$('#as'+astro).addClass('activeThumb');
	
	// Change pic
	$('#picture').attr({ src: 'image.php?path='+lastPhotos[astro]+'&resize=1' })
	
	// change Text
	$('#picText').html(lastPhotosTXT[astro]);
	
  currentImage = astro;  
	picNum = picNumComment = astro;

	$('#picNum').html( picNum );
	$('#picNumComment').html( picNumComment );
	
	//Scroll controls to current element
	var LeftScroll = 65*astro-260;
	$('#photoSlideThumbNav').scrollLeft(LeftScroll);
	oldAstroScroll = oldAstro = astro;
	
	document.getElementById('iframeBanner').src = "photo_right_banner.html";
}

var oldAstroScroll = oldAstro;

function ScrollAstro(direction, totalNumber) {
	// move step
	if(direction == 'next') {
		oldAstroScroll += 1;
		if(oldAstroScroll > totalNumber ) oldAstroScroll = 1;
	}
	else {
		oldAstroScroll -= 1;
		if(oldAstroScroll < 1 ) oldAstroScroll = totalNumber;
	}
	
	ShowAstro(oldAstroScroll);
}

/******* PHOTO GALLERY Version 1 END ********/

/******* PHOTO GALLERY Version 2 START ********/
var currentThumbImage = 1;
var oldThumbAstro=1;
var prevThumbImage = 1;

function nextThumbImage()
{
  var maxImages = document.getElementById('maxImages').value;
  prevThumbImage = currentThumbImage;

  if(currentThumbImage < Math.ceil(maxImages/12)) currentThumbImage += 1;
  else { currentThumbImage = 1;  picNum = 1; picNumComment = 1; }

  document.getElementById('photoSlideThumb'+prevThumbImage).style.display = 'none';
  document.getElementById('photoSlideThumb'+currentThumbImage).style.display = ''; 
  document.getElementById('asNum'+currentThumbImage).className = 'activeSlide';
  
  if(prevThumbImage) document.getElementById('asNum'+prevThumbImage).className = 'a';
  $('#picNumThumb').html( picNum );
  $('#picNumCommentThumb').html( picNumComment );
  
  //Scroll controls to current element and get picture alt tag
	var LeftScroll = 22*currentImage;
	$('#photoSlideThumbNav').scrollLeft(LeftScroll);	
	oldThumbAstroScroll = oldThumbAstro = currentThumbImage;
}

function slideThumbOne() 
{
  var maxImages = document.getElementById('maxImages').value;
  
  if (picNum > Math.ceil(maxImages/12)) //reset number in comment if max size is reached
  {
    picNum = picNumComment = 1;
    $('#picNumThumb').html( picNum );
    $('#picNumCommentThumb').html( picNumComment );
  }
  else 
  {
    $('#picNumThumb').html( ++picNum );
    $('#picNumCommentThumb').html( ++picNumComment );
  }	
  
  nextThumbImage();
  timerID = setTimeout(slideThumbOne, interval);
}

function ShowThumbView(astro) //the same as ShowAstro
{
	// Select button	
	$('#asNum'+oldThumbAstro).removeClass();
	$('#asNum'+astro).addClass('activeSlide');
	$('#photoSlideThumb'+oldThumbAstro).hide();
	$('#photoSlideThumb'+astro).show();
	
  currentThumbImage = astro;  
	picNum = picNumComment = astro;
  $('#picNumThumb').html( picNum );
  $('#picNumCommentThumb').html( picNumComment );
  
	//Scroll controls to current element
	var LeftScroll = 22*astro-110;	
	$('#photoSlideNavWrapper').scrollLeft(LeftScroll);
	oldThumbAstroScroll = oldThumbAstro = astro;
}

function SlideThumbs(stop)
{
  //If stop is set to 0, make slide=1 and stop scrolling
  if (stop == 0) 
  {
    slide = 1;
    $('#pgpPlay').removeClass();
    $('#pgpPlay').addClass('pgpPlay');
  }
  
  if(slide == 0) {
    slide = 1;
    timerID = setTimeout(slideThumbOne, interval);
  }
  else {
    slide = 0;
    clearTimeout(timerID);
    ShowThumbView( oldThumbAstro );
  }
}

var oldThumbAstroScroll = oldThumbAstro;

function ScrollThumbs(direction, totalNumber) 
{
	// move step
	if(direction == 'next') {
		oldThumbAstroScroll += 1;
		if(oldThumbAstroScroll > totalNumber ) oldThumbAstroScroll = 1;
	}
	else {
		oldThumbAstroScroll -= 1;
		if(oldThumbAstroScroll < 1 ) oldThumbAstroScroll = totalNumber;
	}
	
	ShowThumbView(oldThumbAstroScroll);
}

/******* PHOTO GALLERY Version 2 END ********/

window.onload = function() { ShowAstro( oldAstro ); ShowThumbView( oldThumbAstro ); } 

//Changes PHOTO alt tag value
function changePhotoAlt(divId, picNumber)
{
  if (document.getElementById(divId+picNumber)) 
  {
    var images = document.getElementById(divId+picNumber);
  }
  
  if (images) $('#picText').text(images.alt);
}
/******* END PHOTO GALLERY FUNCTIONS ********/	

/******* FACEBOOK SCRIPT START *********/
function fbs_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function loadImage( path, id ){
	var container = $('#'+id);
	
	//send request
	$.post("ajaxResponder.php", { photo: "1", path: path },
		  function(data){
		    container.html(data);
	});	
}
/******* FACEBOOK SCRIPT END *********/