/******* 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 ********/

/******* 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 ********/

/******* Tabs START ********/
		$(document).ready(function(){
			$('div#caTabs > div').hide(); // Hide all divs
			$('div#caTabs > div:first').show(); // Show the first div
			$('div#caTabs ul li a:first').addClass('select'); // Set the class of the first link to active
			$('div#caTabs ul li a').click(function(){ //When any link is clicked
			$('div#caTabs ul li a').removeClass('select'); // Remove active class from all links
			$(this).addClass('select'); //Set clicked link class to active
			var currentTab1 = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
			$('div#caTabs > div').hide(); // Hide all divs
			$(currentTab1).show(); // Show div with id equal to variable currentTab
			return false;
			});
		});
		$(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 ********/

/******* Accent START ********/
		$(function() {
			$('#accentpause').click(function() { $('#accentSlide').cycle('pause'); return false; });

			$('#accentSlide').cycle({
				fx: 'fade',
				speed: 400,
				timeout: 3000,
				delay:  -4000,
				next: '#accentnext',
				prev: '#accentprev',
				pause: true
			});			
		});
/******* Accent END ********/

/******* RIGHT VIDEO AND PHOTO TABS AND SLIDE START ********/
		$(document).ready(function(){
			$('div#videoPhotoBlock > div').hide(); // Hide all divs
			$('div#videoPhotoBlock > div:first').show(); // Show the first div
			$('div#videoPhotoBlock ul li a:first').addClass('select'); // Set the class of the first link to active
			$('div#videoPhotoBlock ul li a').click(function(){ //When any link is clicked
			$('div#videoPhotoBlock 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#videoPhotoBlock > div').hide(); // Hide all divs
			$(currentTab).show(); // Show div with id equal to variable currentTab
			return false;
			});
		});
		$(function() {
			$('#videoSlide').cycle({ 
				fx: 'scrollLeft', 
				speed: 'fast', 
				delay: 200,
				timeout: 0, 
				next: '#videosNext',
				prev: '#videosPrev',
				pager: '#videoNav',
				pagerAnchorBuilder: function(idx, slide) { 
					// return selector string for existing anchor 
					return '#videoNav a:eq(' + idx + ')'; 
				}
			});
		});
		$(function() {
			$('#photoSlide').cycle({ 
				fx: 'scrollLeft', 
				speed: 'fast', 
				delay: 300,
				timeout: 0, 
				next: '#photosNext',
				prev: '#photosPrev',
				pager: '#photoNav',
				pagerAnchorBuilder: function(idx, slide) { 
					// return selector string for existing anchor 
					return '#photoNav a:eq(' + idx + ')'; 
				}
			});
		});
/******* RIGHT VIDEO AND PHOTO TABS AND SLIDE START ********/

/******* MORE CATEGORY SLIDE START ********/
		$(function() {
			$('#moreCatSlide').cycle({ 
				fx: 'scrollLeft', 
				speed: 'fast', 
				delay: 300,
				timeout: 0, 
				next: '#mcNext',
				prev: '#mcPrev',
				pager: '#mcNav',
				pagerAnchorBuilder: function(idx, slide) { 
					// return selector string for existing anchor 
					return '#mcNav a:eq(' + idx + ')'; 
				}
			});
		});
/******* MORE CATEGORY SLIDE END ********/

/******* ASTRO START ********/
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var date = currentTime.getDate();

var oldAstro=1;

if (month == 3 && date >=21 || month == 4 && date <=19) { oldAstro=1; }
if (month == 4 && date >=20 || month == 5 && date <=20) { oldAstro=2; }
if (month == 5 && date >=21 || month == 6 && date <=21) { oldAstro=3; }
if (month == 6 && date >=22 || month == 7 && date <=22) { oldAstro=4; }
if (month == 7 && date >=23 || month == 8 && date <=22) { oldAstro=5; }
if (month == 8 && date >=23 || month == 9 && date <=22) { oldAstro=6; }
if (month == 9 && date >=23 || month == 10 && date <=22) { oldAstro=7; }
if (month == 10 && date >=23 || month == 11 && date <=21) { oldAstro=8; }
if (month == 11 && date >=22 || month == 12 && date <=21) { oldAstro=9; }
if (month == 12 && date >=22 || month == 1 && date <=19) { oldAstro=10; }
if (month == 1 && date >=20 || month == 2 && date <=18) { oldAstro=11; }
if (month == 2 && date >=19 || month == 3 && date <=20) { oldAstro=12; }
   	

function ShowAstro( astro ) {
	
	// Select button
	$('#as'+oldAstro).removeClass();
	$('#as'+astro).addClass('zActive');
	
	// Change content
	$('#zodiac'+oldAstro).hide();
	$('#zodiac'+astro).show();
	
	// scroll controls to current element
	var LeftScroll = 58 * astro-116;
	
	$('#zodiacContainer').scrollLeft( LeftScroll );
	
	oldAstroScroll = oldAstro = astro;
}
var oldAstroScroll = oldAstro;
function ScrollAstro( direction ) {
	
	// move step
	if(direction == 'next') {
		oldAstroScroll += 1;
		if(oldAstroScroll > 12 ) oldAstroScroll = 1;
	}
	else {
		oldAstroScroll -= 1;
		if(oldAstroScroll < 1 ) oldAstroScroll = 12;
	}
	
	ShowAstro( oldAstroScroll );
}
function MaesureZodiac(){
	
	var zodBlockMaxH = 0 ;
	var curHeight;
	
	for (var i=0; i<=12; i++){
		
	
		curHeight = $('#zodiac'+i).height();
		if(curHeight > zodBlockMaxH) zodBlockMaxH = curHeight;
	
	}
	
	$('#zodiacInfo').height(zodBlockMaxH+45);
}
window.onload = function() { ShowAstro( oldAstro ); MaesureZodiac(); } 

/******* ASTRO END **********/
var q = 0;
var count=21;

function LoadWeather(){
interval = window.setInterval("ShowCity()",4000);
}

function ShowCity() {
	var city_name = $('#weatherCity');
	var city_temp = $('#weatherTemp');
	var city_like = $('#weatherTempLike');
	var city_url = document.getElementById('wurl');
	var wcity = document.getElementById('wcity');
	var city_img = document.getElementById('wimg');	
	
	if(q >=0 ){
	  q++;
	}
	if(q > count-1){
		q=1;
		window.clearInterval(interval);
		LoadWeather();
	}
	
	city_name.html(city['name_'+q]);
	city_temp.html(city['temp_'+q]);
	city_like.html(city['like_'+q]);
	city_url.href = city['url_'+q];
	city_img.src = city['img_'+q];
	city_img.alt = city['desc_'+q];
	city_img.title = city['desc_'+q];
}

/* Snimka na denq */
var OldPhoto = 1;
var scrollPhoto = 1;
function setSnimka( num ){
	
	// Set width of ul
	$('#photoContainer ul').width(70*maxPhoto);
	
	// Change pic
	$('#SnimkaDenq').attr({ src: 'image.php?path='+lastPhotos[num]+'&w=375&h=230' })
	
	// change Text
	$('#photoHover').html(lastPhotosTXT[num]);
	
	// change class to .zActive
	$('#miniPhoto'+OldPhoto).removeClass('zActive');
	$('#miniPhoto'+num).addClass('zActive');
	
	// scroll controls to current element
	var LeftScroll = 70 * num-140;
	
	$('#photoContainer').scrollLeft( LeftScroll );
	
	OldPhoto = num;
}

function ScrollPhoto( direction ) {
	
	// move step
	if(direction == 'next') {
		scrollPhoto += 1;
		if(scrollPhoto > maxPhoto ) scrollPhoto = 1;
	}
	else {
		scrollPhoto -= 1;
		if(scrollPhoto < 1 ) scrollPhoto = maxPhoto;
	}

	setSnimka( scrollPhoto );
}