/******* 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'); 
				$(currentW).toggle(); 
				return false;			
			});
		});		
/******* Weather Right Block 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#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;
			});
		});
/******* Tabs END ********/

/******* Accent START ********/
		$(function() {
			$('#accentpause').click(function() { $('#accentSlide').cycle('accentpause'); return false; });

			$('#accentSlide').cycle({
				fx: 'fade',
				speed: 400,
				timeout: 3000,
				delay:  -4000,
				next: '#accentnext',
				prev: '#accentprev',
				pause: true
			});			
		});
/******* Accent END ********/

/******* Photo Block Hover START ********/
		$(document).ready(function(){
			$('#photoContent').hover(
				function() { $('#photoHover').fadeIn(); },
				function() { $('#photoHover').fadeOut(); }
			);return false;
		});
/******* Photo Block Hover END ********/

/******* Accordion START ********/
		$(document).ready(function(){			
			$('#accordion div div:first').show();
			$(function() {
				$("#accordion").accordion({
					header: 'h3',
					clearStyle: true
				});
			});
		});
/******* Accordion END ********/

/******* Zodiac START ********/
		$(document).ready(function(){
			$('div#zodiacBlock a.zodiacChoose').click(function(){ //When link (Избери зодия) is clicked
				$('div#zodiacBlock > div').hide(); // Hide all divs
				$('div#chooseZodiac').show();
				return false;			
			});			
			$('div#chooseZodiac ul li a').click(function(){ //When link(зодия) is clicked
				$('div#zodiacBlock > div#chooseZodiac').hide(); // Hide div with chooseZodiac id
				var currentZ = $(this).attr('href'); // Set variable currentZ to value of href attribute of clicked link
			    $(currentZ).show();  // Show div with id equal to variable currentZ
				return false;
			});
			$('div#chooseZodiac h2 a').click(function(){ //When link(Хороскоп) is clicked
				$('div#zodiacBlock > div').hide(); // Hide all divs
				$('div#zodiacBlock > div:not(.zodiac)').show(); // Show current zodiac
				return false;
			});			
		});
/******* Zodiac END ********/

/******* Currencies START ********/
		$(document).ready(function(){
			$('div#currenciesContent li:even').addClass('odd'); //Adding class 'odd' on odd lists		
		});
/******* Currencies END ********/

/******* ASTRO START ********/
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var date = currentTime.getDate();
var hours = currentTime.getHours()


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
	$('#zodiac'+oldAstro).removeClass('zodiac');
	$('#zodiac'+oldAstro).addClass('clearfix');
}

/******* 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 );
}
/******* ASTRO END ********/



