document.createElement("article");
document.createElement("aside");
document.createElement("footer");
document.createElement("header");
document.createElement("hgroup");
document.createElement("section");
document.createElement("nav");





function hoverPortfolio(){
	jQuery('.portfolio-items li ').hover(function(){
		
		jQuery(this).find('.p-link').stop().animate({'margin-left':'0', 'margin-bottom':'0'},300);
		jQuery(this).find('.p-enlarge').stop().animate({'margin-right':'0', 'margin-top':'0'},300, function(){
			jQuery(this).parent().find('.post-info').fadeIn('900');
			jQuery(this).parent().find('img').stop().fadeTo('700',0.2);
		
		});
		},function(){
		jQuery(this).find('.post-info').fadeOut('fast');
		jQuery(this).find('img').stop().fadeTo('fast',1);
		jQuery(this).find('.p-link').stop().animate({'margin-left':'-45', 'margin-bottom':'-45'},300);
		jQuery(this).find('.p-enlarge').stop().animate({'margin-right':'-45', 'margin-top':'-45'},300);
	});
}

function hidecontent(){
		jQuery('#wrapper:visible').fadeOut('fast');
		jQuery('#hidecontent').hide();
		jQuery('#showcontent').show();		
	}

function showcontent(){
		jQuery('#wrapper:hidden').fadeIn('fast');
		jQuery('#showcontent').hide();
		jQuery('#hidecontent').show();
	}
	
jQuery(document).ready(function($){


$('a#goback').click(function(){
	
	history.back();
	return false;

	});

/*
$('.module:nth-child(1n)').addClass('module-dark');
$('.module:nth-child(2n)').addClass('module-light');
$('.module:nth-child(3n)').addClass('module-grey');
*/

$('.infobtn').click(function(){
	
	$(this).parent().parent().find('.post-meta-popup').slideDown();
	return false;
	});
	
$('.close-info-popup').click(function(){
	
	$(this).parent().slideUp();
	return false;
	});


$('#hidecontent').click(function(){
	
	hidecontent();
	return false;
	});
	
	
	
$('#showcontent').click(function(){ 
	
		showcontent();
		return false;
	});
		
	

$("a[data-rel^='prettyPhoto']").prettyPhoto({theme: 'pp_default'});

$('.open_modal').click(function(){
		$('#modal_signup').fadeIn();
		return false;
	});

$('a#closemodal').click(function(){
		$('#modal_signup').fadeOut();
		return false;
	});
	
$('#signupform_nav > a').click(function(){
		var connected = jQuery(this).attr('data-rel');
		$('#signup, #signin, #reset').hide();
		$('#' + connected).fadeIn();
	});


$('.epicgallery').each(function () {
        $(this).epicGallery();
    });

$('.fullscreen_gallery_container').epicGalleryFullscreen(); 

jQuery.fn.equalizeHeights = function(){
  return this.height( Math.max.apply(this, jQuery(this).map(function(i,e){ return jQuery(e).height() }).get() ) )
}			
		
//$('.module-featured .page ').equalizeHeights();
//$('.portfolio-grid .portfolio ').equalizeHeights();			
				
				
jQuery('.portfoliofilter li:first').addClass('current-menu-item');

// get the action filter option item on page load
  var $filterType = jQuery('.portfoliofilter li.current-menu-item a').attr('class');
  var $holder = jQuery('ul.portfolio-items');
  var $data = $holder.clone();

  // attempt to call Quicksand when a filter option
  // item is clicked
  jQuery('.portfoliofilter li a').click(function(e) {
   
    // reset the active class on all the buttons
    jQuery('.portfoliofilter li').removeClass('current-menu-item');

    var $filterType = jQuery(this).attr('class');
    
    jQuery(this).parent().addClass('current-menu-item');
    if ($filterType == 'showall') {
       var $filteredData = $data.find('li');
    }
    else {
      var $filteredData = $data.find('li[data-type~=' + $filterType + ']');
    }

    // call quicksand and assign transition parameters
    $holder.quicksand($filteredData, {
      duration: 800,
      easing: 'easeInOutQuad'
      },function(){
      
      	hoverPortfolio();
      	$("a[rel^='prettyPhoto']").prettyPhoto();
        
      }
     );
    
    
    return false;
  });

	hoverPortfolio();
			




// Add tooltip to social media icons
jQuery('.epic_socialmedia > li > a').simpletooltip();



jQuery.fn.setAllToMaxHeight = function(){
return this.height( Math.max.apply(this, jQuery.map( this , function(e){ return jQuery(e).height() + 30}) ) );
}

jQuery('span.caption').setAllToMaxHeight();	

//jQuery('#content, #sidebar').setAllToMaxHeight();

jQuery('.breakline a').click(function(){
	jQuery('html, body').animate({scrollTop: jQuery("#wrapper").offset().top}, 1000);
	return false;
});






/* Cycle slideshow 
==================================================================*/

var cycle_transition = jQuery('#slideshow').attr('data-transition');
var cycle_interval = jQuery('#slideshow').attr('data-interval');

	jQuery('#cycle-slideshow').cycle({
	fx: cycle_transition,
	speed:300,
	easing: 'easeInOutQuad',
	cleartype:  1,
	pause:1,
	timeout: cycle_interval,
	next:  '#next-slide',
	prev:  '#prev-slide',
	before: startPreloader,
	after: onAfter,
	pager: '#thumbnav',
	pagerAnchorBuilder: function(idx, slide) { 
       		 		return '#thumbnav li:eq(' + idx + ') a'; 
       		 		}

	});	



jQuery('#controls a').not('#cycle_pauseButton, #cycle_playButton, #showthumbnails').click(function(){
	//alert('stop');
	jQuery('.preload_slide').stop();
	jQuery('.preload_slide').css({'width':'0px'});
	startPreloader();
	return false;
});

jQuery('#showthumbnails').click(function(){
	
	jQuery(this).hide();
	jQuery('#hidethumbnails').show();
	jQuery('#thumbnav-wrap').slideDown('fast');
	return false;
	
});

jQuery('#hidethumbnails').click(function(){
	
	jQuery(this).hide();
	jQuery('#showthumbnails').show();
	jQuery('#thumbnav-wrap').slideUp('fast');
	return false;
	
});


jQuery('#cycle_pauseButton').click(function(){
	
	jQuery(this).hide();
	jQuery('#cycle_playButton').show();
	jQuery('#cycle-slideshow').cycle('pause');
	resetPreloader();
	return false;
	
});

jQuery('#cycle_playButton').click(function(){
	
	jQuery(this).hide();
	jQuery('#cycle_pauseButton').show();
	jQuery('#cycle-slideshow').cycle('resume');
	startPreloader();
	return false;
});


function startPreloader(){
	
	if(jQuery('#cycle_pauseButton').is(':visible')){
	
	var preloader = jQuery('.preload_slide');
	jQuery(preloader).stop().animate({'width':'0px'},0);
	jQuery(preloader).stop().animate({'width':'100%'}, (cycle_interval - 10), 'linear');
	}else{
	jQuery(preloader).stop().animate({'width':'0px'},0);
	}
	
}

function resetPreloader(){
	
	var preloader = jQuery('.preload_slide');
	jQuery(preloader).stop().animate({'width':'0px'},0);
	}
	
	
function onAfter(cure,next,opts) {
	var caption = (opts.currSlide + 1) + ' / ' + opts.slideCount;
	jQuery('#counter').html(caption);
	
	if((opts.currSlide + 5) < opts.slideCount){
	var currpos = - (opts.currSlide * 160);
	jQuery('#thumbnav').animate({'marginLeft': currpos + 'px'},700,'easeInOutSine');
	}
}


$('#cycle-slideshow').hover(function(){
	
	 $('.preload_slide').pause();}
	 , function() {
  	 $('.preload_slide').resume();
  	});
  	
  	
/* End cycle scripts */

jQuery('span.caption').setAllToMaxHeight();

/*
jQuery('#epic_gallery_wrap').hover(function(){

	jQuery('#epic_gallery_nav').fadeIn();
	},function(){
	jQuery('#epic_gallery_nav').fadeOut();
	});
*/


jQuery('#epic_gallery_nav li a').css({'opacity':'0.4'});
jQuery('#epic_gallery_nav li.activeSlide a').css({'opacity':'1'});

jQuery('#epic_gallery_nav li a').click(function(){
	jQuery('#epic_gallery_nav li a').css({'opacity':'0.4'});
	jQuery('#epic_gallery_nav li.activeSlide a').css({'opacity':'1'});
});



accordionMenu();
toggleMenu();
primaryHover();
tabPanel();


sidebarheight = jQuery('#sidebar').height();
contentheight = jQuery('#content').height();

if(contentheight > sidebarheight){
jQuery('#sidebar').not('.home #sidebar').css({'height': contentheight +'px'});
}
else if(contentheight < sidebarheight){
jQuery('#content').not('.home #content').css({'height': sidebarheight +'px'});
}



}); /* End document.ready */


/*
// Fix z-indexing issues in internet explorer 8.0
if(jQuery.browser.msie && jQuery.browser.version=="8.0"){
jQuery(function() {
	var zIndexNumber = 1000;
	jQuery('div').not('#slideshow-fixed div').each(function() {
		jQuery(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
});
}

*/

  
  
 
function primaryHover(){
	
		jQuery("#menu-primary .sub-menu, #epic_user_menu ul ul").hover(function(){
			jQuery(this).parent().find("a").addClass("primary-active");
			},function(){
			jQuery(this).parent().find("a").removeClass("primary-active");
			
		});
	
}


// TAB PANEL
function tabPanel(){
	
		//Default Action
			jQuery(".tabs .tabcontent").hide(); //Hide all content
			
			
			jQuery('.tabs').each(function(){
				jQuery(this).find(".epic_tabnav > li:first").addClass("current-menu-item").show(); //Activate first tab
				jQuery(this).find(".tabcontent:first").show(); //Show first tab content
			
			});
			
			
				
			
			//On Click Event
			jQuery(".epic_tabnav > li").click(function() {
				jQuery(this).parent().find("li").removeClass("current-menu-item"); //Remove any "active" class
				jQuery(this).addClass("current-menu-item"); //Add "active" class to selected tab
				var activeTab = jQuery(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content

				jQuery(this).parent().parent().find(".tabcontent").hide();
				jQuery(this).parent().parent().find('div:[data-id='+activeTab+']').fadeIn('fast');	
				return false;
			});
			
	
	}
	

	
// TOGGLE
function toggleMenu(){
	
	 

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

function accordionMenu(){

	//Set default open/close settings
	jQuery('.acc_container').hide(); //Hide/close all containers
	//jQuery('.acc_handle:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

	//On Click
	jQuery('.acc_handle').click(function(){
	
	if( jQuery(this).next().is(':hidden') ) { //If immediate next container is closed...
		jQuery('.acc_handle').removeClass('active').next().slideUp('fast'); //Remove all "active" state and slide up the immediate next container
		jQuery(this).toggleClass('active').next().slideDown('fast'); //Add "active" state to clicked trigger and slide down the immediate next container
	}
	
	return false; //Prevent the browser jump to the link anchor
});

}






/*********************
//* jQuery Multi Level CSS Menu #2- By Dynamic Drive: http://www.dynamicdrive.com/
//* Last update: Nov 7th, 08': Limit # of queued animations to minmize animation stuttering
//* Menu avaiable at DD CSS Library: http://www.dynamicdrive.com/style/
*********************/

//Update: April 12th, 10: Fixed compat issue with jquery 1.4x

//Specify full URL to down and right arrow images (23 is padding-right to add to top level LIs with drop downs):


// Run the script...
var siteurl = jQuery("meta[name=siteurl]").attr('content');
var arrowimages={down:['downarrowclass', siteurl + '/library/images/arrow_down.png', 18], right:['rightarrowclass', siteurl +'/library/images/arrow_right.png']}

var jqueryslidemenu={

animateduration: {over: 200, out: 100}, //duration of slide in/ out animation, in milliseconds

buildmenu:function(menuid, arrowsvar){
	jQuery(document).ready(function($){
		var $mainmenu=$("#"+menuid+">ul")
		var $headers=$mainmenu.find("ul").parent()
		$headers.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
			this.istopheader=$curobj.parents("ul").length==1? true : false
			$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
			
			$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
				'<img src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
				+'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
				+ '" style="border:0;" />'
			)
			$curobj.hover(
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					var menuleft=this.istopheader? 0 : this._dimensions.w
					menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
					if ($targetul.queue().length<=1) //if 1 or less queued animations
						$targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).slideDown(jqueryslidemenu.animateduration.over)
				},
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					$targetul.slideUp(jqueryslidemenu.animateduration.out)
				}
			) //end hover
			$curobj.click(function(){
				$(this).children("ul:eq(0)").hide()
			})
		}) //end $headers.each()
		$mainmenu.find("ul").css({display:'none', visibility:'visible'})
	}) //end document.ready
}
}

//build menu with ID="primary" on page:
jqueryslidemenu.buildmenu("primary", arrowimages),
jqueryslidemenu.buildmenu("epic_user_menu", arrowimages),
jqueryslidemenu.buildmenu("filter", arrowimages);



// 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);
		
		
		maxwidth = jQuery('#kwicks').width() - 80;
		//alert (divwidth);
			
		jQuery('.kwicks').kwicks({
			
			max :  maxwidth,
			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();				
		});
});




/* 
 * 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;
    }
}



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


/**
*
*	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 + 12;
				var tipY = e.pageY + 12;
				$(this).attr("title", ""); 
				$("body").append("<div id='simpleTooltip' style='position:absolute; z-index: 9999; display: none;'>" + text + "</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 - 10;
				var tipY = e.pageY - 40;
				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);



/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright © 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);


/*
 * Pause jQuery plugin v0.1
 *
 * Copyright 2010 by Tobia Conforto <tobia.conforto@gmail.com>
 *
 * Based on Pause-resume-animation jQuery plugin by Joe Weitzel
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or(at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 

(function(){var e=jQuery,f="jQuery.pause",d=1,b=e.fn.animate,a={};function c(){return new Date().getTime()}e.fn.animate=function(k,h,j,i){var g=e.speed(h,j,i);g.complete=g.old;return this.each(function(){if(!this[f]){this[f]=d++}var l=e.extend({},g);b.apply(e(this),[k,e.extend({},l)]);a[this[f]]={run:true,prop:k,opt:l,start:c(),done:0}})};e.fn.pause=function(){return this.each(function(){if(!this[f]){this[f]=d++}var g=a[this[f]];if(g&&g.run){g.done+=c()-g.start;if(g.done>g.opt.duration){delete a[this[f]]}else{e(this).stop();g.run=false}}})};e.fn.resume=function(){return this.each(function(){if(!this[f]){this[f]=d++}var g=a[this[f]];if(g&&!g.run){g.opt.duration-=g.done;g.done=0;g.run=true;g.start=c();b.apply(e(this),[g.prop,e.extend({},g.opt)])}})}})();


// Epic gallery


(function ($) {
    // Fetch the image
    $.fn.image = function (src, f) {
        return this.each(function () {
            var i = new Image();
            i.onload = f;
            i.src = src;
            this.appendChild(i);
        });
    }
    

    $.fn.epicGallery = function (targetId) {
        var target = $(this),
            targetId = $(this).attr('id'),
            targetObj = "#" + targetId,
            loaderObj = "#" + targetId + "-loader",
            loader = '.loader';
        // Load First image
        var $imageNum = 0;
        var $maxslides = $(this).find('.inlinegallery li').size(); // Get number of images
        var imageurl = $(this).find('.' + targetId + '-link_0 a').attr('href');
        var imageheight = $(this).find('.' + targetId + '-link_0 a').attr('data-rel');
		 
        var previousBtn = '.button_prev'; // Previous slide button
        var nextBtn = '.button_next'; // Previous slide button
        
        $('#nav li a:first').addClass('active');
        
        // Inline gallery initial setup
        $(targetObj + ' .postgallery').append('<div class="gallery_backdrop"></div><div id="' + loaderObj + '" class="loader"></div>');
        
        $(targetObj).find('.loader').image(imageurl, function () {
        $('.loader').find('img').clone().appendTo('.gallery_backdrop');	
        });
        $(targetObj).find('.loader img').animate({
            'height': imageheight + 'px'
        },500, function(){
			   
			  });
        //$(".gallery_caption").html('<p><span class="captiontitle">' + imagecaption + '</span>' + imagedescription + '</p>' );
        //galleryCaptionIn();
        $('#' + targetId).find('.button_next').click(function (e) {
            $imageNum++;
            if ($imageNum == $maxslides) {
                $imageNum = 0;
            }
            slide();
            return false;
        });
        $('#' + targetId).find('.button_prev').click(function (e) {
            $imageNum--;
            if ($imageNum < 0) {
                $imageNum = $maxslides - 1;
            }
            slide();
            return false;
        });
        
        $('#nav li a').click(function(e) {
        	
        	//$(this).addClass('active');
        	$imageNum = $(this).attr('data-rel');
        		slide();
            return false;
        });
        
        
        // This is where the actual slide is done

        function slide() {
        		$('#nav li a').removeClass('active');
        		
        		
			    var previmageheight = $('.' + targetId + '-link_' + $imageNum - 1 + ' a').html();
				imageheight = $('.' + targetId + '-link_' + $imageNum + ' a').attr('data-rel');
				imageurl = $('.' + targetId + '-link_' + $imageNum + ' a').attr('href');
				            
            //$(targetObj).find('.button_prev').fadeOut('fast');
			//$(targetObj).find('.button_down').fadeOut('fast');
            
            
            $(targetObj).find('.loader').animate({
                'opacity': '0'
            }, 300, function () {
			 $(targetObj).animate({'height': imageheight + 'px'}, 300, function(){
					
					document.getElementById(loaderObj).innerHTML = ''; // Clear image
					 
                	$(targetObj).find('.loader').image(imageurl, function () {
                											
                        $(targetObj).find('.loader').animate({
                            'opacity': '1'
                        }, 500, function(){
                        	$('.gallery_backdrop').find('img').remove();
                        	$('.loader').find('img').clone().appendTo('.gallery_backdrop');
                        	
                        });
						//$(targetObj).find('.button_prev').fadeIn('fast');
						//$(targetObj).find('.button_down').fadeIn('fast');
                     	$('#nav .' + targetId + '-link_' + $imageNum + ' a').addClass('active');
                     	
                });
                																	  
			  });
               
            });
        }

    };
})(jQuery);



/* Fullscreen gallery */

(function ($) {
    // Fetch the image
    $.fn.image = function (src, f) {
        return this.each(function () {
            var i = new Image();
            i.onload = f;
            i.src = src;
            this.appendChild(i);
        });
    }
    

    $.fn.epicGalleryFullscreen = function (targetId) {
        var target = $(this),
            targetId = $(this).attr('id'),
            targetObj = "#" + targetId,
            loaderObj = "#" + targetId + "-loader",
            loader = '.loader';
        // Load First image
        var $imageNum = 0;
        var $maxslides = $(this).find('.inlinegallery li').size(); // Get number of images
        var imageurl = $(this).find('.' + targetId + '-link_0 a').attr('href');
                
		
		var imagecaption =  $(this).find('.' + targetId + '-link_0 a').attr('data-title');
		var imagedescription = $(this).find('.' + targetId + '-link_0 a').attr('data-description');
		
        var previousBtn = '.fg_prev'; // Previous slide button
        var nextBtn = '.fg_next'; // Previous slide button
        
        $('.inlinegallery li a:first').addClass('active');
        
        // Inline gallery initial setup
        $(targetObj + ' .postgallery').append('<div class="gallery_backdrop"></div><div id="' + loaderObj + '" class="loader"></div>');
        
        $(targetObj).find('.loader').image(imageurl, function () {
        	$('.loader > img').clone().appendTo('.gallery_backdrop');
        	$(".gallery_backdrop img").fullBg();
        	$(".loader img").fullBg();
        		
        });
      
        $(".gallery_caption").html('<h3>' + imagecaption + '</h3><p>' + imagedescription + '</p>' );
        
        //galleryCaptionIn();
        $('#' + targetId).find('.fg_next').click(function (e) {
        	$('.inlinegallery li a').removeClass('active');
        	
            
            $imageNum++;
           
            if ($imageNum == $maxslides) {
                $imageNum = 0;
            }
            
             $('.inlinegallery li:nth-child('+ ($imageNum + 1) +') a').addClass('active');
             
            hidecontent();
        	$('#showcontent').fadeIn();
            slide();
            return false;
        });
        $('#' + targetId).find('.fg_prev').click(function (e) {
        	
        	$('.inlinegallery li a').removeClass('active');
        	
            $imageNum--;
            
            if ($imageNum < 0) {
                $imageNum = $maxslides - 1;
            }
            $('.inlinegallery li:nth-child('+ ($imageNum + 1) + ') a').addClass('active');
            hidecontent();
        	$('#showcontent').fadeIn();
            slide();
            return false;
        });
        
        
        
        $('.inlinegallery li a').click(function(e) {
        	
        	$('.inlinegallery li a').removeClass('active');
        	$(this).addClass('active');
        	$imageNum = $(this).attr('data-count');
        	hidecontent();
        	$('#hidecontent, #showcontent').fadeIn();
        	slide();
        	
            return false;
        });
        
        
        // This is where the actual slide is done

        function slide() {
        
        	$(".gallery_caption").html('');
        	
        	var imagecaption =  $('.' + targetId + '-link_' + $imageNum + ' a').attr('data-title');
			var imagedescription = $('.' + targetId + '-link_' + $imageNum + ' a').attr('data-description');
		
        	$(".gallery_caption").html('<h3>' + imagecaption + '</h3><p>' + imagedescription + '</p>' );
        	
        	
        	$('#preloader').fadeIn();
        	$(".gallery_backdrop img").fullBg();
        	
        	//$('#nav li a').removeClass('active');
        		
        	imageurl = $('.' + targetId + '-link_' + $imageNum + ' a').attr('href');
		            
            $(targetObj).find('.loader').animate({
                'opacity': '0'
            }, 200, function () {
				
					$('.loader > img').remove();
					
					 
                	$(targetObj).find('.loader').image(imageurl, function () {
                		$('#preloader').fadeOut('fast'); 
                		$(".loader img").fullBg();
                		   											
                        $(targetObj).find('.loader').animate({
                            'opacity': '1'
                        }, 1000, function(){
                                
                                                
                        	$('.gallery_backdrop').find('img').remove();
                        	$('.loader > img').clone().appendTo('.gallery_backdrop');
                        	$(".gallery_backdrop img").fullBg();
                        });
 	
                });
   
            });
        }

    };
})(jQuery);

/**
 * jQuery.fullBg
 * Version 1.0
 * Copyright (c) 2010 c.bavota - http://bavotasan.com
 * Dual licensed under MIT and GPL.
 * Date: 02/23/2010
**/
(function($) {
  $.fn.fullBg = function(){
    var bgImg = $(this);		
 
    function resizeImg() {
      var imgwidth = bgImg.width();
      var imgheight = bgImg.height();
 
      var winwidth = $(window).width();
      var winheight = $(window).height();
 
      var widthratio = winwidth / imgwidth;
      var heightratio = winheight / imgheight;
 
      var widthdiff = heightratio * imgwidth;
      var heightdiff = widthratio * imgheight;
 
      if(heightdiff>winheight) {
        bgImg.css({
          width: winwidth+'px',
          height: heightdiff+'px'
        });
      } else {
        bgImg.css({
          width: widthdiff+'px',
          height: winheight+'px'
        });		
      }
    } 
    resizeImg();
    $(window).resize(function() {
      resizeImg();
    }); 
  };
})(jQuery)

jQuery(function(){
    //Get our elements for faster access and set overlay width
    var div = jQuery('#thumbs'),
                 ul = jQuery('ul.inlinegallery'),
                 // unordered list's left margin
                 ulPadding = 10;

    //Get menu width
    var divWidth = div.width();

    //Remove scrollbars
    div.css({overflow: 'hidden'});

    //Find last image container
    var lastLi = ul.find('li:last-child');

    //When user move mouse over menu
    div.mousemove(function(e){

      //As images are loaded ul width increases,
      //so we recalculate it each time
      var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
      var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
      div.scrollLeft(left);
    });
});
