$(document).ready(function(){
		
	// Comment Box Expansion (like Facebook)
	$("#comment, .wpcf7 textarea").elastic();
	$("#comment, .wpcf7 textarea").blur(function(){
		if (this.value == '') {
			$(this).animate({"height": "23px"}, "fast");
		}
	});
	
	// Navigation Dropdowns
	$("ul.navigation-top-ul").superfish();
	$("ul.navigation-top-ul ul li:last-child a").addClass("no-border");
	$("ul.sidebar-subpages > ul > li:last-child a").addClass("no-border");
	$("li.widget > ul > li:last-child a").addClass("no-border");
	$('.category-switch-list > ul li:last-child').addClass("no-border");
	
	
	$('#category-switcher').hoverIntent(function(){
		$(this).addClass('point-down');					 
		$(this).find('.category-switch-list').slideDown("fast");										 
	}, function(){
		$(this).removeClass('point-down');		
		$(this).find('.category-switch-list').hide();
	});
	
	
	if (galleryType) {
		$('.view').removeClass('active');
		$('#'+galleryType).addClass('active');
	} else {
		$('#list').addClass('active');
	}
	
	// View Switcher
	$(".view-switcher > .view").click(function(){
		if (animationOn == false) {
			$('.view').removeClass('active');
			$(this).addClass('active');
		}
	});
	
	// Full View Hover Faders
	$(".view-block").hover(function(){
		$(this).find(".single-image-block-fader").fadeIn(300);
	}, function(){
		$(this).find(".single-image-block-fader").fadeOut(300);
	});
	
	
	/* ---------------------------------- */
	/* View Styles AJAX Loader            */
	
	// START IF GALLERYTYPE
	if (galleryType) {
		
		function getFromURL(name){
			name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
			var regexS = "[\\?&]"+name+"=([^&#]*)";
			var regex = new RegExp( regexS );
			var results = regex.exec( window.location.href );
			if( results == null ){
				return "";
			} else {
				return results[1];
			}
		}

		// Show Loading Graphic
		function showLoading(){
			loading.show();
		}
		//hide loading bar
		function hideLoading(){
			loading.fadeOut("fast",function(){
				new_content.fadeIn("normal");
				animationOn = false;
			});
		}

		var viewType = getFromURL('type');

		// Category Dropdown List
		var currentCatList=new Array();
		var countItOut = 0;
		$(".category-switch-list a").each(function(){ 
			currentCatList[countItOut] = [this.href];
			var currentHREF = this.href;
			if (viewType) {
				var newHREF = '?type='+viewType;
			} else {
				var newHREF = '?type=thumb';
			}
			$(this).attr("href",currentHREF +''+ newHREF);
			countItOut++;
		});
		
		// Breadcrumbs list
		var breadCatList=new Array();
		var countItOut = 0;
		$("#breadcrumbs a").each(function(){ 
			breadCatList[countItOut] = [this.href];
			if (countItOut > 0) {
				var currentHREF = this.href;
				if (viewType) {
					var newHREF = '?type='+viewType;
				} else {
					var newHREF = '?type=thumb';
				}
				$(this).attr("href",currentHREF +''+ newHREF);
			}
			countItOut++;
		});
		
		// References  
		var views = $(".view-switcher > .view-ajax");
		var loading = $("#loading");
		var new_content = $('#featured-area');
		var animationOn = true;
		
		showLoading();
		new_content.hide();
		new_content.load(templateURL+"/views/"+galleryType+".php", galleryData, hideLoading);
		
		//Manage click events
		views.click(function(){
							 
			galleryData = $(this).attr('rel');
							 
			if (animationOn == false && this.id != current_view) {
				
				animationOn = true;
							 
				//load selected section
				switch(this.id){
					case "list":
						if (current_view != "list") {
							showLoading();
							new_content.hide();
							new_content.load(templateURL+"/views/list.php", galleryData, hideLoading);
							current_view = "list";
							
							countItOut = 0;
							$(".category-switch-list a").each(function(){
								var currentHREF = currentCatList[countItOut];
								var newHREF = '?type=list';
								$(this).attr("href",currentHREF +''+ newHREF);
								countItOut++;
							});
							
							countItOut = 0;
							$("#breadcrumbs a").each(function(){
								if (countItOut > 0) {
									var currentHREF = breadCatList[countItOut];
									var newHREF = '?type=list';
									$(this).attr("href",currentHREF +''+ newHREF);
								}
								countItOut++;
							});
						}
						break;
					case "thumb":
						if (current_view != "thumb") {
							showLoading();
							new_content.hide();
							new_content.load(templateURL+"/views/thumb.php", galleryData, hideLoading);
							current_view = "thumb";
							
							countItOut = 0;
							$(".category-switch-list a").each(function(){
								var currentHREF = currentCatList[countItOut];
								var newHREF = '?type=thumb';
								$(this).attr("href",currentHREF +''+ newHREF);
								countItOut++;
							});
							
							countItOut = 0;
							$("#breadcrumbs a").each(function(){
								if (countItOut > 0) {
									var currentHREF = breadCatList[countItOut];
									var newHREF = '?type=thumb';
									$(this).attr("href",currentHREF +''+ newHREF);
								}
								countItOut++;
							});
						}
						break;
					default:
						//hide loading bar if there is no selected section
						hideLoading();
						break;
				}
			}
		});
	} // END IF GALLERYTYPE
	
	
	
});
