//jQuery.noConflict();

jQuery(window).load(function() {
									  
	var nivo_slider_effect = jQuery("meta[name=nivo_slider_effect]").attr('content');
	var nivo_slider_timeout = jQuery("meta[name=nivo_slider_timeout]").attr('content');
	var nivo_slider_slices = jQuery("meta[name=nivo_slider_slices]").attr('content');
	

	
	if(nivo_slider_effect){								  
    jQuery('#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	 
	});
};
});
									  

jQuery(document).ready(function(){
					
					
			var portfolioexcerpt = jQuery("meta[name=portfolio_excerpt_tooltip]").attr('content');	
			if(portfolioexcerpt != "true"){
			jQuery(".pf").simpletooltip();
			}
					
			sliderHover();		
			gallerySliderHover();
			cycleSliderHover();
			
			// PRETTYPHOTO
			jQuery("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(!jQuery.browser.msie){
			jQuery("#logo").hover(function(){
					jQuery("#logo img").stop().fadeTo("slow", 0.5); 
					},function(){
					jQuery("#logo img").stop().fadeTo("slow", 1); 
			
			});
			}
			
			// CYCLE GALLERY
			jQuery('#gallerycycle').cycle({
			  fx: 'fade',
			  speed:300,
			  easing: 'easeInOutQuad',
			  cleartype:  1,
			  pause:0,
			  timeout: 0,
			  next:  '#next-gallery',
			  prev:  '#prev-gallery'
			});		
			
			jQuery('#gallerySliderCycle').cycle({
			  fx: 'fade',
			  speed:300,
			  easing: 'easeInOutQuad',
			  cleartype:  1,
			  pause:0,
			  timeout: 0,
			  next:  '#next-gallery-slider',
			  prev:  '#prev-gallery-slider'

			});		
			
			jQuery('#portfoliocycle').cycle({
			  fx: 'fade',
			  speed:300,
			  easing: 'easeInOutQuad',
			  cleartype:  1,
			  pause:0,
			  timeout: 3000
			  //next:  '#next-gallery',
			  //prev:  '#prev-gallery'

			});		
			
		
			// CYCLE SLIDERS
			
			var home_slider_effect = jQuery("meta[name=cycle_slider_effect]").attr('content');
			var home_slider_timeout = jQuery("meta[name=cycle_slider_timeout]").attr('content');
			
			jQuery('#cycle div:first').fadeIn(1000, function() {	 
			jQuery('#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(){
		
			
		jQuery('.portfolio_all').addClass("active");
			
		// Show hide categories
		jQuery('.portfoliofilter').click(function(){
		jQuery('.portfoliofilter, .portfolio_all').removeClass("active");
		jQuery(this).addClass("active");
		var selected_term = jQuery(this).attr('id');
		
		
		
		jQuery('.pf').each(function(){
			
			if(jQuery(this).hasClass(selected_term)){
				jQuery(this).animate({'opacity' : '1'});
				//jQuery(this).fadeOut('fast').delay('200').fadeIn();
				}
			else{
				jQuery(this).animate({'opacity' : '0.3'});}
				//jQuery(this).fadeOut('fast');}
			});
		
		return false;
	});
	// Show all posts	
	jQuery('.portfolio_all').click(function(){
		//jQuery('.pf:hidden').fadeIn();			
		jQuery('.pf').animate({'opacity' : '1'});
		jQuery('.portfoliofilter').removeClass("active");
		jQuery(this).addClass("active");
		return false;
	});
}

function portfolioListFilter(){
		
			
		jQuery('.portfolio_all').addClass("active");
			
		// Show hide categories
		jQuery('.portfoliofilter').click(function(){
		jQuery('.portfoliofilter, .portfolio_all').removeClass("active");
		jQuery(this).addClass("active");
		var selected_term = jQuery(this).attr('id');
		
		
		jQuery('.pfl').each(function(){
			
			if(jQuery(this).hasClass(selected_term)){
				jQuery(this).fadeOut('fast').delay('200').fadeIn();
				}
			else{
				jQuery(this).fadeOut('fast');}
			});
		
		return false;
	});
	// Show all posts	
	jQuery('.portfolio_all').click(function(){
		jQuery('.pfl:hidden').fadeIn();			
		
		jQuery('.portfoliofilter').removeClass("active");
		jQuery(this).addClass("active");
		return false;
	});
}


function primaryHover(){
	
		
		var coMain ='#primary-menu ul li ';
		var coSub  ='#primary-menu ul div';
		
		jQuery(coSub).hover(function(){
			jQuery(this).parent().find("a").not('ul ul a',this).addClass("primary-active");
			},function(){
			jQuery(this).parent().find("a").not('ul ul a',this).removeClass("primary-active");
			
		});
		
		jQuery('#primary-menu ul li').not('#primary-menu ul ul li').hover (
		
         function (evt) {
			jQuery('div:hidden',this).slideDown(200);
			 },function (evt) {
           jQuery('div',this).slideUp(100);}
    		);
		
	
}

function secondaryHover(){
	
		jQuery("#secondary-menu ul ul").hover(function(){
			jQuery(this).parent().find("a").addClass("secondary-active");
			},function(){
			jQuery(this).parent().find("a").removeClass("secondary-active");
			
		});
	
}

function sliderHover(){
	
		
		jQuery("#feature-wrap").hover(function(){
			jQuery(this).find(".p-slide, .n-slide").stop().fadeTo('fast', 1);
			},function(){
			jQuery(this).find(".p-slide, .n-slide").stop().fadeTo('fast', 0);
		});
	
}
// Main slider
function cycleSliderHover(){
	
		jQuery("#next-slide, #prev-slide").hide();
		jQuery("#slider").hover(function(){
			jQuery(this).find("#next-slide, #prev-slide").stop().fadeTo('fast', 1);
			},function(){
			jQuery(this).find("#next-slide, #prev-slide").stop().fadeTo('fast', 0);
		});
	
}




function gallerySliderHover(){
	
		jQuery("#next-gallery-slider, #prev-gallery-slider").hide();
		jQuery("#gallery_slider_wrap").hover(function(){
			jQuery(this).find("#next-gallery-slider, #prev-gallery-slider").stop().fadeTo('fast', 1);
			},function(){
			jQuery(this).find("#next-gallery-slider, #prev-gallery-slider").stop().fadeTo('fast', 0);
		});
	
}

// TAB PANEL
function tabPanel(){
	
		//Default Action
			jQuery(".tabcontent").hide(); //Hide all content
			jQuery(".tabcontentwide").hide(); //Hide all content
			jQuery("#tabnav li:first, #simpletabnav li:first, #minimaltabnav li:first").addClass("active").fadeIn('fast'); //Activate first tab
			jQuery(".tabcontent:first").show(); //Show first tab content
			jQuery(".tabcontentwide:first" ).show(); //Show first tab content
			
			//On Click Event
			jQuery("#tabnav li, #simpletabnav li, #minimaltabnav li").click(function() {
				jQuery("#tabnav li, #simpletabnav li, #minimaltabnav li").removeClass("active"); //Remove any "active" class
				jQuery(this).addClass("active"); //Add "active" class to selected tab
				jQuery(".tabcontent").hide(); //Hide all content
				jQuery(".tabcontentwide").hide() //Hide all content
				var activeTab = jQuery(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
				jQuery(activeTab).stop().fadeIn('fast'); //Fade in the active content
				return false;
			});
	
	}
	


	
// HOVER EFFECT ON PORTFOLIO/GALLERY IMAGES
function portfolioHover(){
			// PORTFOLIO AND GALLERY ZOOM
			jQuery(".portfolio .zoom").css({'opacity':'0'});
			jQuery(".portfolio").hover(function(){
					jQuery(".zoom",this).stop().fadeTo("slow", 1); 
					},function(){
					jQuery(".zoom",this).stop().fadeTo("slow", 0);  
			
			});
			
			
			/*jQuery(".portfolio").hover(function(){
					jQuery(this).stop().fadeTo("medium", 0.8); 
					},function(){
					jQuery(this).stop().fadeTo("slow", 1);  
			
			});*/
			}

// TOGGLE
function toggleMenu(){
	
	jQuery(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	jQuery("p.trigger").click(function(){
		jQuery(this).toggleClass("active").next().slideToggle("slow");
		return false; //Prevent the browser jump to the link anchor
	});
						
}

// OPEN LINKS IN NEW WINDOW
jQuery(function() {
	jQuery('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
/*jQuery(function() {
	var zIndexNumber = 1000;
	jQuery('div').each(function() {
		jQuery(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
});*/



	
// ACCORDION SLIDER EVENT HANDLERS

jQuery(function () {
	
	jQuery('.slideimage').hide();
	jQuery('.slide-minicaption').hide();
	jQuery('.slidecaption').hide();
});


jQuery(window).bind("load", function() {
		
		
		
		//jQuery(".slidecaption").hide();
		jQuery(".slidecaption").css({'opacity':'0'});
		jQuery('.slide-minicaption').show();
		//jQuery('.slidecaption').show();
		jQuery('.slideimage:hidden').fadeIn(500);
		jQuery(".slide-minicaption").fadeTo(1, 0.8);
		
				
		jQuery('.kwicks').kwicks({
			
			max :  760,
			spacing:0
		});

});

jQuery(function(){ 
		jQuery(".accslide").hover(function() {
		jQuery(".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(){
		jQuery(".slide-minicaption",this).stop().animate({opacity: 0.8},200, 'easeOutSine');
		jQuery(".slidecaption",this).stop().animate({opacity: 0, bottom: '-20'}, 200, 'easeInSine').hide();				
		});
});



/**
*
*	simpleTooltip jQuery 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");
			});
		}
	});
}})(jQuery);
