/* 	
	Index of this JS File

	(01) On Load Scripts
	(02) Tab Script
	(03) Toggles
	(04) Hide Information Boxes (Close Button)
	(05) Filterable Pack / Sortable Portfolio	
	(06) Testimonial Rotator
	(07) Image Hover Fade Effect	
	(08) Custom Popup
	(09) Contact Form
	(10) Form Field Over Labels
	(11) Scroll to Top Control
	(12) Search Form
	(13) Hover Intent - Compressed File 	
*/


/* ========================================================== 
	(02) Tab Script
============================================================ */

$(document).ready(function() {

	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

/* ========================================================== 
	(03) Simple and Accordion Toggles
============================================================ */

$(document).ready(function(){	
	// Simple Toggle script start
	$(".toggle_container").hide();
	$("p.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle(350);
	});
	
	$(".toggle_container2").hide();
	$("p.trigger2").click(function(){
		$(this).toggleClass("active2").next().slideToggle(350);
	});
	
	//--Toggle Accrordation Script
	
	//Set default open/close settings
	$('.acc_container').hide(); //Hide/close all containers
	//$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

	//On Click
	$('.acc_trigger').click(function(){
		if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
			$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
			//$(this).toggleClass('active').previous().slideUp(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
			$(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container	
		}else{
			$(this).toggleClass('active').next().slideUp();
		}
		return false; //Prevent the browser jump to the link anchor
	});
	
	//Set default open/close settings
	$('.acc_container2').hide(); //Hide/close all containers
	//$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

	//On Click
	$('.acc_trigger2').click(function(){
		if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
			$('.acc_trigger2').removeClass('active2').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
			$(this).toggleClass('active2').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container	
		}else{
			$(this).toggleClass('active2').next().slideUp();
		}
		return false; //Prevent the browser jump to the link anchor
	});
	
});

/* IMPORTED THEDAWN THEME TOGGLES */
$(function() {
	
	$('.faq-block') .children('p, br') .remove();//.next('p, br') .remove();
	$('.faq-answer, .toggle-content') .css('display', 'none');
	
	$.each($('.toggle-block'), function() {
		$(this) .children('br') .remove();
	});
	
	$('.faq-q, .toggle-t') .click(function() {
		$(this) .toggleClass('toggle-open');
		$(this) .next('.faq-answer, .toggle-content') .slideToggle(100);
	});
	
	$('.toggle-block .box-title-style-1, .toggle-block .box-title-style-2') .click(function() {
		$(this) .next('.toggle-block .box-text') .slideToggle(100);
	});
	
	$('.toggle-block .box-title-style-1, .toggle-block .box-title-style-2') .hover(function() {
		$(this) .prev('span.handle') .css('display', 'block');
	}, function() {
		$(this) .prev('span.handle') .css('display', 'none');
	});
	
});

/* ========================================================== 
	(04) Hide Information Boxes (Close Button)
============================================================ */

function hide_boxes(){
	$('span.hide-boxes').click(function() {
		$(this).parent().fadeOut();					   
	});	
}



/* ========================================================== 
	(06) Testimonial Rotator
============================================================ */

$(document).ready(function(){
	$('#testimonials-rotate .testimonial-slide');
	setInterval(function(){
		$('#testimonials-rotate .testimonial-slide').filter(':visible').fadeOut(1000,function(){
			if($(this).next('div.testimonial-slide').size()){
				$(this).next().fadeIn(1000);
			}
			else{
				$('#testimonials-rotate .testimonial-slide').eq(0).fadeIn(1000);
			}
		});
	},6000); // fadein fadeout slider delay time eg. 1000 it less and 10000 is more.	
});

/* ========================================================== 
	(07) Image Hover Fade Effect
============================================================ */

jQuery(window).load(function() { 	
	jQuery(".fade-img").show();
	jQuery(".fade-img img").fadeTo('normal', 1, function() {		
		$get_id = jQuery(this).parent().parent().attr("lang");
		if($get_id != ""){
			jQuery(this).parent().parent().addClass($get_id);			
			$(this).hover(function(){
				$(this).fadeTo('normal', 0.2);
				
			}, function() {
					$(this).fadeTo('normal', 1);
			});
		}
    });
});


/* ========================================================== 
	(08) Custom Popup
============================================================ */

$(document).ready(function() {

//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close" title="Close"><span class="btn_close">Close</span></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=30)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=30)'}) is used to fix the IE Bug on fading transparencies 

    return false;
});

//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
    return false;
});

});



