$(document).ready(function(){
		//When you click on a link with class of poplight and the href starts with a # 
		$('a.poplight[href^=#]').click(function() {
			var popID = $(this).attr('rel'); //Get Popup Name
			var popURL = $(this).attr('href'); //Get Popup href to define size
					
			//Pull Query & Variables from href URL
			var query= popURL.split('?');
			var dim= query[1].split('&');
			var popWidth = dim[0].split('=')[1]; //Gets the first query string value
	
			//Fade in the Popup and add close button
			$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');
			
			//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
			var popMargTop = ($('#' + popID).height()) / 2;
			var popMargLeft = ($('#' + popID).width()) / 2;
			
			//Apply Margin to Popup
			$('#' + popID).css({ 
				'margin-top' : -popMargTop,
				'top' : 50 + '%',
				'margin-left' : -popMargLeft
			});
			
			//Fade in Background
			$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
			$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
			
			return false;
		});
		
		
		//Close Popups and Fade Layer
		$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
			$('#fade , .popup_block').fadeOut(function() {
				$('#fade, a.close').remove();  
		}); //fade them both out
			
		return false;
	});
});
        
 function ucfirst( str ) {
	var f = str.charAt(0).toUpperCase();
	return f + str.substr(1, str.length-1);
}

$(function() {
	var tabs = $('ul.tabs');
	
    for(k1 in settings){
        tabs.append($('<li><a href="#'+k1+'" class=""><span>'+ucfirst(k1)+'</span></a></li>'));   
    }
    
    $("ul.tabs li:first a").addClass("current");
    
}); 


var onTabClick = function(myTab) {
	var tabId = myTab + '1';
	var $container 	= $(tabId);
	
	$(".tab_content").hide();
	
	if ($container.attr('loaded')) {
		$container.parent().show();
		return;
	}
	
	$container.attr('loaded', '1');
	
    var size = images_count;
    var folder;
    var more;
    var _tab = myTab.substr(1);
    
	size = settings[_tab].total_image_qty;
	folder = settings[_tab].folder;
	
    more = (size > images_count); 
	
    var images = (more ? size : images_count);
    var rel = 'prettyPhoto[' + _tab + ']';
    
	for(var i=1; i <= size; i++) {
		var path = 'images/' + folder + '/' + i + '.jpg';
		var pathSmall = 'images/' + folder + '/small/' + i + '.jpg';
		
        var a = $('<a/>');
        
        if (i > images_count) {
        	a.addClass('hidden');
        }
        
        var img = $('<img/>').attr('src', pathSmall);
        a.attr('href', path).addClass('pretty').attr('rel', rel).append(img);
        
        $container.append(a);
	}

    $(myTab + " a.pretty").prettyPhoto();
	
    $container.parent().fadeIn(1000);

    //$(".hidden").hide();

	if (more) {
		$(myTab + ' .loadmore').click(function() {
			$(this).hide();
			$(myTab + " a.pretty.hidden").fadeIn(1500).removeClass('hidden');
			return false;
		});
	} else { 
		$(myTab + ' .loadmore').hide();
	}
};


$(function(){
	var tab = "fashion"; 

	onTabClick('#' + tab);
      
	$("ul.tabs li").click(function() {
		var activeTab = $(this).find("a").attr("href");

	    $("ul.tabs li.active").removeClass("active");
		$(this).addClass("active");
		
		onTabClick(activeTab);
		return false;
	});
	
	$('#menu a').click(function(){
		$('#menu a').removeClass('current');
		$(this).addClass('current');
	});
});
