jQuery(document).ready(function($) {
	
	//search keyword value
	(function(){
		var item = $('#fSearch');
		var newTxt = item.attr("title");
		item.attr("value",newTxt);
	    item.focus(function () {
			if (item.attr("value") == newTxt) {
				item.attr("value","");
			}
	    });
		item.blur(function () {
			if (item.attr("value") == "") {
				item.attr("value", newTxt);
			}
	    });
	})();
	
	 
	 	
	//Customisable Automated Slideshow function ------------------------
	
	//Setup
		
	var slideShowType = "fade";
		
	//Initiate --
		
	$('.slideshowWrapper li').hide();
	
	$('.slideshowWrapper li:first').show();
	
	$('.slideshowWrapper').append("<ul class='slideShowNavigation'><li id='next'><a href='#'><span>Next</span></a></li><li id='prev'><a href='#'><span>Previous</span></a></li></ul>");

	$('.slideshowWrapper').append("<ol class='slideShowPagination'></ol>");
		
	$('.slideshowWrapper .slideshow li').each( function(i){
		
		no = i + 1;
		
		$(this).addClass('item' + i);
		
		$('.slideShowPagination').append("<li><a href='#' id='pagi" + i + "'><span>" + no + "</span></a></li>");
		
	})

	$('.slideShowPagination li:first').addClass('active');
	
	//When a Navigation item is clicked --
	
	$('.slideShowNavigation li a').click( function(){
		
		var current = $('.slideshow li:visible').attr('class').substring($('.slideshow li:visible').attr('class').length - 1);
		
		if($(this).parent('li').attr('id') == "next"){
	
			if(current == $('.slideshowWrapper .slideshow li').length -1){
				
				//alert("Next is empty");
				current = -1;
				
			}
			
			nextItem = parseInt(current) + 1;
		
		} else {

			if(current == "0"){
				
				//alert("Next is empty");
				current = $('.slideshowWrapper .slideshow li').length;
				
			}
			
			nextItem = parseInt(current) - 1;
			
			
		}
		
		$('.slideShowPagination li').removeClass('active');
		$('.slideShowPagination li a#pagi' + nextItem).parent('li').addClass('active');//Current active pagination
		
		if(slideShowType == "fade"){
			
		
			$('.slideshow li').hide();	
		
			$('.slideshow li.item' + nextItem).fadeIn(3000);
		
		} else if(slideShowType == "slide"){
			
			//slide rules
			
		}
			
		return false;
		
	})	
	
	//When a Pagination item is clicked --
	
	$('.slideShowPagination li a').click( function(){
		
		clearInterval(timer);
		
		$('.slideShowPagination li').removeClass('active');
		$(this).parent('li').addClass('active');//Current active pagination
		
		var whichItem = $(this).attr('id').substring($(this).attr('id').length - 1);
		
		$('.slideshow li').hide();	
		
		$('.slideshow li.item' + whichItem).fadeIn(3000);
		
		return false;
		
	})
	
	var timer = setInterval("$('.slideShowNavigation li#next a').click()", 8000);
	
	
	
	/* -- Artist Portfolio Slideshow -- */
	
	$('.gallery-wrapper').addClass('sliderActive');
	
	$('.gallery-wrapper').append("<ul class='artistPortfolioNav'><li class='next'><a href='#'><span>Next</span></a></li><li class='prev'><a href='#' class='da'><span>Prev</span></a></li></ul>");
	
	var current = 0;
	
	var listArray = $('ul.gallery li');
	var total = listArray.length - 4;
	
	$('ul.gallery').width( 90 * listArray.length);
	
	//alert($('ul.gallery').width());
	
	
	/* -- When Nav clicked -- */
	
	$('.artistPortfolioNav li a').click( function(){
		
		if($(this).parent().attr('class') == "next"){
			
			//alert(current + " - " + total)
			
			if(current <= total){
			
			$('ul.gallery').animate({"left": "-=179px"}, "slow");
			
			current = current + 2;
			
			$('.prev').children('a').removeClass('da');
			
			} else {
				
			$('ul.gallery').animate({"left": "0px"}, "fast");
				
			current = 0;
			
			$('.prev').children('a').addClass('da');
			
			}
			
			
		} else {
			
			//alert("prev");
			
			//alert(current + " - " + total)
			
			if(current != 0){
			
			$('ul.gallery').animate({"left": "+=179px"}, "slow");
			
			if(current == 2){
				
				$('.prev').children('a').addClass('da');				
				
			}			
			
			current = current - 2;
				
			} else {
				
				
				$('.prev').children('a').addClass('da');
				
			}
			
		}
			
		return false;
		
	})
	
	
	
	
	
	
	/* -- Email sign up form (homepage) -- */
	
	$(".emailSign .frmRow input").val($(".emailSign .frmRow input").siblings('label').text());
	
	
	$(".emailSign .frmRow input").focus( function() {
		
		if( this.value == $(this).siblings('label').text()) {
			
			this.value = "";
		}
		
	}).blur(function() {
		
		if( !this.value.length ) {
			
			this.value = $(this).siblings('label').text();
			
		}
	
	});
	// lightbox
	$('.stock-item li').each( function(){
		if($(this).attr('class')!='nojs')
		{
			$(this).append("<a href='" + $(this).children('a').attr('href') + "' class='zoom nyroModal'><img src='../wp-content/themes/agnews/images/design/ico-zoom.png' alt='' title='Enlarge this image' /></a>")
		}
	})

	$('.image-utilitys li a').addClass('nyroModal');
	
	$('.nyroModal').nyroModal();
	
	
	$(function() {
	$.nyroModalSettings({
	    endShowContent: function(elts) {
	      	$('#nyroModalContent img').click(function(){
				$('#closeBut').trigger('click');	
				return false;
			});
	    }
	  });
	});
	
});
