/*=================================================== Custom jQuery functions. ===================================================*/ ///////////////////////////////////////////// // NO CONFLICT ///////////////////////////////////////////// var $j = jQuery.noConflict(); var onLoad = { init: function(){ slider_main.init(); var deviceAgent = navigator.userAgent.toLowerCase(); var agentID = deviceAgent.match(/(iphone|ipad|ipod|android)/); if (!agentID) { header.init(); } nav.init(); portfolioAjax.init(); onePageAjax.init(); portfolioSorting.init(); prettyPhoto.init(); contactForm.init(); reloadFunctions.init(); baseFunctions.init(); } }; $j(document).ready(function(){ $j("#menu-main-menu").find("a").each(function(i,e) { $j(this).addClass($j(this).attr('title')); }); $j("#menu-main-menu").find("a").mouseover(function() { $j(this).data('title', $j(this).attr('title')); $j(this).attr('title',''); }); $j("#menu-main-menu").find("a").mouseout(function() { $j(this).attr('title', $j(this).data('title') ); }); $j("#jsu_news_section").load("http://www.jsums.edu/wp-content/themes/jsumain/js/listnews-cache.html #news_list"); }); ///////////////////////////////////////////// // HEADER ///////////////////////////////////////////// var header = { init: function () { var $header = $j('#header-section'), $logo = $j('#logo').find('img'), $nav = $j('#main-navigation'), $window = $j(window), $headerIsDynamic = true; $headerIsDynamic = false; if ($headerIsDynamic) { $window.scroll(function () { if ($window.scrollTop() > 70 && $window.width() > 959) { // header.animate($header, $logo, $nav); } else { setTimeout(function () { if ($window.scrollTop() < 70) { //header.reset($header, $logo, $nav); } }, 700); } }); } }, animate: function ($header, $logo, $nav) { $header.filter(':not(:animated)').animate({ "height": 53, "borderTopWidth": 5 }); $logo.filter(':not(:animated)').animate({ "height": 31 }); $nav.filter(':not(:animated)').animate({ "marginTop": 16, "marginBottom": 16 }); }, reset: function ($header, $logo, $nav) { $header.filter(':not(:animated)').animate({ "height": 95, "borderTopWidth": 10 }); $logo.filter(':not(:animated)').animate({ "height": 75 }); $nav.filter(':not(:animated)').animate({ "marginTop": 38, "marginBottom": 38 }); } }; ///////////////////////////////////////////// // NAVIGATION ///////////////////////////////////////////// var nav = { init: function(){ // Main Nav var $body = $j('body'), $current_page = $j('.current-menu-item'), $header = $j('#header-section'), $logo = $j('#logo').find('img'), $nav = $j('#main-navigation').find('ul.menu'), $window = $j(window); var $offset = 0, $standard_offset = 0, $home_offset = -145; $headerIsDynamic = true; $headerIsDynamic = false; if ($window.width() < 1024) { $standard_offset = -15; } else if (!$headerIsDynamic) { $standard_offset = -70; $j('.section').css('padding-top', '30px'); }else { $standard_offset = -45; } $current_page.addClass('current'); if ($body.hasClass('home')) { var $nav_link_parent = $j('.menu').find('li'); $nav_link_parent.on('click', 'a', function(e) { //alert($j(this).attr('title')); var $nav_link_title = $j(this).attr('title'); if(!$nav_link_title) { $nav_link_title=$j(this).data('title'); } if ($nav_link_title) { e.preventDefault(); } if ($j(this).parent().is(':first-child')) { $offset = $home_offset; } else { $offset = $standard_offset; } var offset2 = $j('#' + $nav_link_title).offset(); /* $j.smoothScroll({ scrollTarget: '#' + $nav_link_title, offset: -300, easing: 'easeInOutExpo', speed: 700 }); */ var ismobile=navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i); if(ismobile) { minus=15; } else { var minus=262;} $j('body,html').animate({'scrollTop':(offset2.top-minus)},700); var $current = $j(this); $nav_link_parent.removeClass('current'); $current.parent().addClass('current'); return false; }); } // Mobile Nav var $mobile_select = $j('.dropdown-menu'); if ($body.hasClass('home')) { $mobile_select.change(function(e) { e.preventDefault(); var $mob_nav_selected = '#' + $j('.dropdown-menu option:selected').attr('class'); if ($mob_nav_selected == '#') { window.location = $j(this).find("option:selected").val(); } else { var offset2 = $j($mob_nav_selected).offset(); /* var $offset = -20; $j.smoothScroll({ scrollTarget: $mob_nav_selected, offset: $offset, easing: 'easeInOutExpo', speed: 700 }); */ $j('body,html').animate({'scrollTop':(offset2.top-15)},700); } }); } else { $mobile_select.change(function() { window.location = $j(this).find("option:selected").val(); }); } } }; // Change menu active when scroll through sections scrolltimer=null; $j(window).scroll(function () { if(scrolltimer) clearTimeout(scrolltimer); scrolltimer=setTimeout(function() { var $inview = $j('#content > section:in-viewport:eq(1)').attr('id'); var $menu_item = $j('.menu > li > a'); var $link = $menu_item.filter('.' + $inview ); if ($link.length && !$link.is('.current')) { $menu_item.parent().removeClass('current'); $link.parent().addClass('current'); } },100) }); ///////////////////////////////////////////// // PORTFOLIO AJAX FUNCTIONS ///////////////////////////////////////////// var portfolioAjax = { init: function(){ var $portfolio_section = $j('#portfolio'), $portfolio_items = $j('.portfolio-items'), $cont = $j('.portfolio-ajax-drawer'), $loading_bay = $j('.loading-bay'), $controls = $j('.controls'), $loading = $j('#portfolio').find('.loading'), $small_loading = $j('#portfolio').find('.small-loading'); var $current = null, $current_item = null, $currentPostID = null, $nextPortfolioPost = null, $prevPortfolioPost = null, $prevPortfolioPostID = null, $nextPortfolioPostID = null; var $offset = -55, $window_width = $j(window).width(); function itemChanged() { $current_item = $j($current).parent().parent(); $current_item.addClass('current-item'); $currentPostID = $j($current).attr('href'); $nextPost = $j($current_item).closest('li.item').next('li.item').find('a.link'); $prevPost = $j($current_item).closest('li.item').prev('li.item').find('a.link'); $prevPostID = $j($prevPost).attr('href'); $nextPostID = $j($nextPost).attr('href'); $controls.find('#portfolio-prev').attr('href', $prevPostID); $controls.find('#portfolio-next').attr('href', $nextPostID); if(typeof $nextPostID == 'string') { $j('a#portfolio-next').show(); } else { $j('a#portfolio-next').hide(); } if(typeof $prevPostID == 'string') { $j('a#portfolio-prev').show(); } else { $j('a#portfolio-prev').hide(); } } function countItems() { var $count = $cont.children().length; if ($count > 1) { $cont.find('article:first-child').remove(); } } function onAfter(curr, next, opts, fwd) { var index = opts.currSlide; //get the height of the current slide var $slide_height = $j(this).outerHeight(true); //set the container's height to that of the current slide $cont.animate({height: $slide_height}); $cont.find('img.size-full').each(function() { $j(this).css("height", "auto"); }); setTimeout(function() { $controls.css('display', 'inline-block'); $small_loading.hide(); }, 1000); } $portfolio_items.on('click','a.link',function(e){ e.preventDefault(); if ($current_item) { $current_item.removeClass('current-item'); } $j.smoothScroll({ scrollTarget: $portfolio_section, offset: $offset }); // Set current item and next/prev controls $current = $j(this); itemChanged(); if ($cont.is(":visible")) { countItems(); $controls.hide(); $small_loading.css('display', 'inline-block'); $loading_bay.load($currentPostID + ' article.type-portfolio', function(response, status, xhr){ var $error = $j("#error"); if (status != 'error') { $cont.append($loading_bay.find('article')); $cont.cycle({ fx: "scrollUp", delay: -4000, autostop: 1, after: onAfter }); slider_main.init(); prettyPhoto.init(); reloadFunctions.init(); } else { $error.html('Error: ' + xhr.status + ' ' + xhr.statusText); } }); } else { $loading.slideDown(400); $cont.load($currentPostID + ' article.type-portfolio', function(response, status, xhr){ var $error = $j("#error"); if (status != 'error') { $loading.hide(); var $bg_image; $bg_image = 'http://www.jsums.edu/wp-content/themes/jsumain/images/portfolio_bg/wood.jpg'; $cont.css('background-image', 'url(' + $bg_image + ')'); $cont.slideDown(600); //get the height of the current slide var $slide_height = $cont.find('article').outerHeight(true); //set the container's height to that of the current slide $cont.animate({height: $slide_height}); $cont.find('img.size-full').each(function() { $j(this).css("height", "auto"); }); $controls.css('display', 'inline-block'); slider_main.init(); prettyPhoto.init(); reloadFunctions.init(); } else { $error.html('Error: ' + xhr.status + ' ' + xhr.statusText); } }); } }); $controls.on('click', 'a#portfolio-close',function(e) { e.preventDefault(); $cont.slideUp(600); $controls.hide(); $current_item.removeClass('current-item'); $j.smoothScroll({ scrollTarget:$portfolio_section, offset: $offset }); }); $controls.on('click', 'a#portfolio-prev',function(e) { e.preventDefault(); $current_item.removeClass('current-item'); $j.smoothScroll({ scrollTarget: $portfolio_section, offset: $offset }); countItems(); $controls.hide(); $small_loading.css('display', 'inline-block'); $loading_bay.load($prevPostID + ' article.type-portfolio', function(response, status, xhr){ var $error = $j("#error"); if (status != 'error') { $cont.append($loading_bay.find('article')); $cont.cycle({ fx: "scrollRight", delay: -4000, autostop: 1, after: onAfter }); slider_main.init(); prettyPhoto.init(); reloadFunctions.init(); } else { $error.html('Error: ' + xhr.status + ' ' + xhr.statusText); } $current = $j($prevPost); itemChanged(); }); }); $controls.on('click', 'a#portfolio-next',function(e) { e.preventDefault(); $current_item.removeClass('current-item'); $j.smoothScroll({ scrollTarget: $portfolio_section, offset: $offset }); countItems(); $controls.hide(); $small_loading.css('display', 'inline-block'); $loading_bay.load($nextPostID + ' article.type-portfolio', function(response, status, xhr){ var $error = $j("#error"); if (status != 'error') { $cont.append($loading_bay.find('article')); $cont.cycle({ fx: "scrollLeft", delay: -4000, autostop: 1, after: onAfter }); slider_main.init(); prettyPhoto.init(); reloadFunctions.init(); } else { $error.html('Error: ' + xhr.status + ' ' + xhr.statusText); } $current = $j($nextPost); itemChanged(); }); }); } }; ///////////////////////////////////////////// // ONE PAGE AJAX FUNCTION ///////////////////////////////////////////// function ajaxResponseParse(response) { var $frame = $j("