/* ==================================================
Custom jQuery functions.
================================================== */
/////////////////////////////////////////////
// NO CONFLICT
/////////////////////////////////////////////
var $j = jQuery.noConflict();
var onLoad = {
init: function(){
page.init();
nav.init();
slider.init();
youtubeChannel.init();
radioShow.init();
contactForm.init();
reloadFunctions.init();
firstWord.init();
lastWord.init();
}
};
/////////////////////////////////////////////
// PAGE FUNCTIONS
/////////////////////////////////////////////
var page = {
init: function () {
var $content = $j('#content'), $footer_widgets = $j('.footer-widgets');
$content.animate({
opacity:1
}, 1000, 'easeInOutQuint');
}
}
/////////////////////////////////////////////
// NAVIGATION
/////////////////////////////////////////////
var nav = {
init: function(){
// Main Nav
$j("ul.sub-menu").parents().addClass('parent');
$j(".menu li.parent").hover(
function() {
$j(this).find('ul.sub-menu:first').css("display", "block");
var $left = "10px";
if ($j(this).find('ul.sub-menu:first').parent().parent().hasClass("sub-menu")) {
$left = $j(this).find('ul.sub-menu:first').parent().parent().outerWidth() - 2;
}
$j(this).find('ul.sub-menu:first').stop().animate({
"opacity": "1",
"left": $left
}, 200);
},
function() {
$j(this).find('ul.sub-menu:first').stop().animate({
"opacity": "0",
"left": "-20px"
}, 200);
hideNav($j(this).find('ul.sub-menu:first'));
}
);
// Mobile Nav
var $mobile_select = $j('.dropdown-menu'), $selected_page_text = $j('.selected-option');
$selected_page_text.html($mobile_select.find('option:selected').text());
$mobile_select.change(function() {
location = $j(this).find("option:selected").val();
});
}
};
/////////////////////////////////////////////
// FLEXSLIDER FUNCTION
/////////////////////////////////////////////
var slider = {
init: function() {
$j('.flexslider').flexslider({
animation: "slide", //String: Select your animation type, "fade" or "slide"
slideDirection: "horizontal", //String: Select the sliding direction, "horizontal" or "vertical"
slideshow: true, //Boolean: Animate slider automatically
slideshowSpeed: 6000, //Integer: Set the speed of the slideshow cycling, in milliseconds
animationDuration: 300, //Integer: Set the speed of animations, in milliseconds
directionNav: false, //Boolean: Create navigation for previous/next navigation? (true/false)
controlNav: false, //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage
keyboardNav: true, //Boolean: Allow slider navigating via keyboard left/right keys
mousewheel: false, //Boolean: Allow slider navigating via mousewheel
prevText: "[", //String: Set the text for the "previous" directionNav item
nextText: "]", //String: Set the text for the "next" directionNav item
pausePlay: false, //Boolean: Create pause/play dynamic element
pauseText: '5', //String: Set the text for the "pause" pausePlay item
playText: '4', //String: Set the text for the "play" pausePlay item
randomize: false, //Boolean: Randomize slide order
slideToStart: 0, //Integer: The slide that the slider should start on. Array notation (0 = first slide)
animationLoop: true, //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end
pauseOnAction: true, //Boolean: Pause the slideshow when interacting with control elements, highly recommended.
pauseOnHover: false, //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering
controlsContainer: "", //Selector: Declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken.
manualControls: "", //Selector: Declare custom control navigation. Example would be ".flex-control-nav li" or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs.
start: function(){
foresight.reload();
}, //Callback: function(slider) - Fires when the slider loads the first slide
before: function(){
foresight.reload();
}, //Callback: function(slider) - Fires asynchronously with each slider animation
after: function(){}, //Callback: function(slider) - Fires after each slider animation completes
end: function(){} //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous)
});
}
}
/////////////////////////////////////////////
// Youtube Channel Slider
/////////////////////////////////////////////
var youtubeChannel = {
init: function() {
$j('#youtube-channel li a').each(function(){
$j(this).click(function(){$j('#youtube-channel-iframe').attr('src', 'http://www.youtube.com/embed/' + $j(this).attr('rel')); return false;});
});
$j('#youtube-channel').jcarousel({
wrap: 'circular',
scroll: 1
});
}
}
/////////////////////////////////////////////
// Radio Shows Slider
/////////////////////////////////////////////
var radioShow = {
init: function() {
$j('#radioshow').jcarousel({
wrap: 'circular',
scroll: 1
});
}
}
/////////////////////////////////////////////
// First Word style
/////////////////////////////////////////////
var firstWord = {
init: function() {
$j('.box-heading h1').each(function(){
var me = $j(this);
me.html( me.text().replace(/(^\w+)/,'$1') );
});
}
}
/////////////////////////////////////////////
// Last Word style
/////////////////////////////////////////////
var lastWord = {
init: function() {
$j('#latest-posts .blog-item .item-title').each(function(){
var me = $j(this);
me.html( me.text().replace(/(\w+)$/,'$1') );
});
}
}
/////////////////////////////////////////////
// CONTACT FORM FUNCTION
/////////////////////////////////////////////
var contactForm = {
init: function() {
$j('form#contactForm').submit(function() {
$j('form#contactForm label.error').remove();
$j('form#contactForm span.error').remove();
var hasError = false;
$j('.requiredField').each(function() {
$this = $j(this);
if($j.trim($this.val()) == '') {
$this.addClass('invalid');
hasError = true;
} else if($this.hasClass('email-input')) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test($j.trim($this.val()))) {
$this.addClass('invalid');
hasError = true;
} else {
$this.removeClass('invalid');
}
} else {
$this.removeClass('invalid');
}
});
if(!hasError) {
$j('form#contactForm li.buttons button').fadeOut('normal', function() {
$j(this).parent().append('');
});
var formInput = $j(this).serialize();
$j.post($j(this).attr('action'),formInput, function(data){
$j('form#contactForm').slideUp("fast", function() {
$j('p.thanks').fadeIn(1000);
});
});
}
return false;
});
}
}
/////////////////////////////////////////////
// RELOAD FUNCTIONS
/////////////////////////////////////////////
var reloadFunctions = {
init:function() {
// Remove title attributes from images to avoid showing on hover
$j('img[title]').each(function() {
$j(this).removeAttr('title');
});
// Button hover tooltips
$j('.tooltip').each( function() {
$j(this).css( 'marginLeft', '-' + Math.round( ($j(this).outerWidth() / 2) ) + 'px' );
});
$j('.tweet-details a').hover( function() {
$j(this).parent().find('.tooltip' ).stop().animate({
bottom: '36px',
opacity: 1
}, 400, 'easeInOutExpo');
}, function() {
$j(this).parent().find('.tooltip').stop().animate({
bottom: '20px',
opacity: 0
}, 400, 'easeInOutExpo');
});
// Tabs Shortcode Function
$j('.tabbed-asset').tabs();
// Accordion Shortcode Function
$j('.accordion').accordion({
collapsible: true,
autoHeight: false
});
}
}
function hideNav($subnav) {
setTimeout(function() {
if ($subnav.css("opacity") == "0") {
$subnav.css("display", "none");
}
}, 300);
}
$j(document).ready(onLoad.init);