

$(window).load(function() {
									  
	var nivo_slider_effect = $("meta[name=nivo_slider_effect]").attr('content');
	var nivo_slider_timeout = $("meta[name=nivo_slider_timeout]").attr('content');
	var nivo_slider_slices = $("meta[name=nivo_slider_slices]").attr('content');
	

	
	if(nivo_slider_effect){								  
    $('#nivo').nivoSlider({
		  effect:nivo_slider_effect, //Specify sets like: 'fold,fade,sliceDown'
        slices:nivo_slider_slices,
        animSpeed:500, //Slide transition speed
        pauseTime:nivo_slider_timeout,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:false, //Next & Prev
        //directionNavHide:true, //Only show on hover
        controlNav:true, //1,2,3...
        //controlNavThumbs:true, //Use thumbnails for Control Nav
        //controlNavThumbsFromRel:false, //Use image rel for thumbs
        //controlNavThumbsSearch: '.jpg', //Replace this with...
        //controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0, //Universal caption opacity
        beforeChange: function(){},
        afterChange: function(){},
        slideshowEnd: function(){}, //Triggers after all slides have been shown
        lastSlide: function(){}, //Triggers when last slide is shown
        afterLoad: function(){} //Triggers when slider has loaded	 
	});
};
});
									  

$(document).ready(function(){
					
					
			var portfolioexcerpt = $("meta[name=portfolio_excerpt_tooltip]").attr('content');	
			if(portfolioexcerpt != "true"){
			$(".pf").simpletooltip();
			}
					
			sliderHover();		
			gallerySliderHover();
			cycleSliderHover();
			
			// PRETTYPHOTO
			//$("a[rel^='prettyPhoto']").prettyPhoto(); 
			
			
			// HOVER EFFECT ON PORTFOLIO/GALLERY THUMBNAILS
			portfolioHover();
			
			// TOGGLE FUNCTION
			toggleMenu();
		
					
			// TAB PANEL
			tabPanel();
			
			portfolioFilter();
			portfolioListFilter();
			
			// PRIMARY MENU HOVER EFFECT
			primaryHover();
			secondaryHover();
			
			// LOGO HOVER FUNCTION
			if(!$.browser.msie){
			$("#logo").hover(function(){
					$("#logo img").stop().fadeTo("slow", 0.5); 
					},function(){
					$("#logo img").stop().fadeTo("slow", 1); 
			
			});
			}
			
			// CYCLE GALLERY
			
		
			// CYCLE SLIDERS
			
			var home_slider_effect = $("meta[name=cycle_slider_effect]").attr('content');
			var home_slider_timeout = $("meta[name=cycle_slider_timeout]").attr('content');
			
			$('#cycle div:first').fadeIn(1000, function() {	 
			$('#cycle').cycle({
			  //fx: $home_slider_effect,
			  fx: home_slider_effect,
			  speed:1000,
			  easing: 'easeInOutQuad',
			  cleartype:  1,
			  pause:1,
			  timeout: home_slider_timeout,
			  prev: '#prev-slide',
				next: '#next-slide'
				});
			});
			

});




function portfolioFilter(){
		
			
		$('.portfolio_all').addClass("active");
			
		// Show hide categories
		$('.portfoliofilter').click(function(){
		$('.portfoliofilter, .portfolio_all').removeClass("active");
		$(this).addClass("active");
		var selected_term = $(this).attr('id');
		
		
		
		$('.pf').each(function(){
			
			if($(this).hasClass(selected_term)){
				$(this).animate({'opacity' : '1'});
				//$(this).fadeOut('fast').delay('200').fadeIn();
				}
			else{
				$(this).animate({'opacity' : '0.3'});}
				//$(this).fadeOut('fast');}
			});
		
		return false;
	});
	// Show all posts	
	$('.portfolio_all').click(function(){
		//$('.pf:hidden').fadeIn();			
		$('.pf').animate({'opacity' : '1'});
		$('.portfoliofilter').removeClass("active");
		$(this).addClass("active");
		return false;
	});
}

function portfolioListFilter(){
		
			
		$('.portfolio_all').addClass("active");
			
		// Show hide categories
		$('.portfoliofilter').click(function(){
		$('.portfoliofilter, .portfolio_all').removeClass("active");
		$(this).addClass("active");
		var selected_term = $(this).attr('id');
		
		
		$('.pfl').each(function(){
			
			if($(this).hasClass(selected_term)){
				$(this).fadeOut('fast').delay('200').fadeIn();
				}
			else{
				$(this).fadeOut('fast');}
			});
		
		return false;
	});
	// Show all posts	
	$('.portfolio_all').click(function(){
		$('.pfl:hidden').fadeIn();			
		
		$('.portfoliofilter').removeClass("active");
		$(this).addClass("active");
		return false;
	});
}


function primaryHover(){
	
		
		var coMain ='#primary-menu ul li ';
		var coSub  ='#primary-menu ul div';
		
		$(coSub).hover(function(){
			$(this).parent().find("a").not('ul ul a',this).addClass("primary-active");
			},function(){
			$(this).parent().find("a").not('ul ul a',this).removeClass("primary-active");
			
		});
		
		$('#primary-menu ul li').not('#primary-menu ul ul li').hover (
		
         function (evt) {
			$('div:hidden',this).slideDown(200);
			 },function (evt) {
           $('div',this).slideUp(100);}
    		);
		
	
}

function secondaryHover(){
	
		$("#secondary-menu ul ul").hover(function(){
			$(this).parent().find("a").addClass("secondary-active");
			},function(){
			$(this).parent().find("a").removeClass("secondary-active");
			
		});
	
}

function sliderHover(){
	
		
		$("#feature-wrap").hover(function(){
			$(this).find(".p-slide, .n-slide").stop().fadeTo('fast', 1);
			},function(){
			$(this).find(".p-slide, .n-slide").stop().fadeTo('fast', 0);
		});
	
}
// Main slider
function cycleSliderHover(){
	
		$("#next-slide, #prev-slide").hide();
		$("#slider").hover(function(){
			$(this).find("#next-slide, #prev-slide").stop().fadeTo('fast', 1);
			},function(){
			$(this).find("#next-slide, #prev-slide").stop().fadeTo('fast', 0);
		});
	
}




function gallerySliderHover(){
	
		$("#next-gallery-slider, #prev-gallery-slider").hide();
		$("#gallery_slider_wrap").hover(function(){
			$(this).find("#next-gallery-slider, #prev-gallery-slider").stop().fadeTo('fast', 1);
			},function(){
			$(this).find("#next-gallery-slider, #prev-gallery-slider").stop().fadeTo('fast', 0);
		});
	
}

// TAB PANEL
function tabPanel(){
	
		//Default Action
			$(".tabcontent").hide(); //Hide all content
			$(".tabcontentwide").hide(); //Hide all content
			$("#tabnav li:first, #simpletabnav li:first, #minimaltabnav li:first").addClass("active").fadeIn('fast'); //Activate first tab
			$(".tabcontent:first").show(); //Show first tab content
			$(".tabcontentwide:first" ).show(); //Show first tab content
			
			//On Click Event
			$("#tabnav li, #simpletabnav li, #minimaltabnav li").click(function() {
				$("#tabnav li, #simpletabnav li, #minimaltabnav li").removeClass("active"); //Remove any "active" class
				$(this).addClass("active"); //Add "active" class to selected tab
				$(".tabcontent").hide(); //Hide all content
				$(".tabcontentwide").hide() //Hide all content
				var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
				$(activeTab).stop().fadeIn('fast'); //Fade in the active content
				return false;
			});
	
	}
	


	
// HOVER EFFECT ON PORTFOLIO/GALLERY IMAGES
function portfolioHover(){
			// PORTFOLIO AND GALLERY ZOOM
			$(".portfolio .zoom").css({'opacity':'0'});
			$(".portfolio").hover(function(){
					$(".zoom",this).stop().fadeTo("slow", 1); 
					},function(){
					$(".zoom",this).stop().fadeTo("slow", 0);  
			
			});
			
			
			/*$(".portfolio").hover(function(){
					$(this).stop().fadeTo("medium", 0.8); 
					},function(){
					$(this).stop().fadeTo("slow", 1);  
			
			});*/
			}

// TOGGLE
function toggleMenu(){
	
	$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$("p.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false; //Prevent the browser jump to the link anchor
	});
						
}

// OPEN LINKS IN NEW WINDOW
$(function() {
	$('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});
});

// JavaScript Document

/* 
 * Cross-browser event handling, by Scott Andrew
 */
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 *
 * by Ross Shannon, http://www.yourhtmlsource.com/
 */

addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}

// Reverses the z-indexing for correcting ie7 z-index issues
/*$(function() {
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
});*/



	
// ACCORDION SLIDER EVENT HANDLERS

$(function () {
	
	$('.slideimage').hide();
	$('.slide-minicaption').hide();
	$('.slidecaption').hide();
});


$(window).bind("load", function() {
		
		
		
		//$(".slidecaption").hide();
		$(".slidecaption").css({'opacity':'0'});
		$('.slide-minicaption').show();
		//$('.slidecaption').show();
		$('.slideimage:hidden').fadeIn(500);
		$(".slide-minicaption").fadeTo(1, 0.8);
		
/*				
		$('.kwicks').kwicks({
			
			max :  760,
			spacing:0
		});
*/
});

$(function(){ 
		$(".accslide").hover(function() {
		$(".slide-minicaption",this).stop().animate({opacity: 0},200, 'easeInSine').parent().find(".slidecaption").show().stop().delay(400).animate({opacity: 0.8, bottom: '20'},400, 'easeOutSine');	
		},function(){
		$(".slide-minicaption",this).stop().animate({opacity: 0.8},200, 'easeOutSine');
		$(".slidecaption",this).stop().animate({opacity: 0, bottom: '-20'}, 200, 'easeInSine').hide();				
		});
});



/**
*
*	simpleTooltip $ plugin, by Marius ILIE
*	visit http://dev.mariusilie.net for details
*
**/
(function($){ $.fn.simpletooltip = function(){
														  
														  
	return this.each(function() {
		var text = $(this).attr("title");
		$(this).attr("title", "");
		if(text != undefined) {
			$(this).hover(function(e){
				var tipX = e.pageX + 50;
				var tipY = e.pageY + 30;
				$(this).attr("title", ""); 
				$("body").append("<div id='simpleTooltip' style='position:absolute; z-index: 100; display: none;'><span>" + text + "</span></div>");
				if($.browser.msie) var tipWidth = $("#simpleTooltip").outerWidth(true)
				else var tipWidth = $("#simpleTooltip").width()
				$("#simpleTooltip").width(tipWidth);
				$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
			}, function(){
				$("#simpleTooltip").remove();
				$(this).attr("title", text);
			});
			$(this).mousemove(function(e){
				var tipX = e.pageX - 150;
				var tipY = e.pageY - 200;
				var tipWidth = $("#simpleTooltip").outerWidth(true);
				var tipHeight = $("#simpleTooltip").outerHeight(true);
				if(tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
				if($(window).height()+$(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
				$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
			});
		}
	});
}})($);
