/*************************** Search Panel Toggle ***************************/

jQuery(document).ready(function(){
	jQuery("#search-box").hide(); 
	
	jQuery("#search-icon").toggle(function(){
		jQuery(this).addClass("active");
		}, function () {
		jQuery(this).removeClass("active");
	});
	
	jQuery("#search-icon").click(function(){
		jQuery(this).next("#search-box").slideToggle('fast');
	});
});


/*************************** Share Toggle ***************************/

jQuery(document).ready(function(){
	jQuery("#share-review").hide(); 
	jQuery("#share-review-link a").html("Share &#9660;");
	
	jQuery("#share-review-link a").toggle(function(){
		jQuery(this).html("Share &#9650;");
		}, function () {
		jQuery(this).html("Share &#9660;");
	});
	
	jQuery("#share-review-link a").click(function(){
		jQuery(this).next("#share-review").slideToggle('fast');
	});
});


/*************************** Transform Select Drop Down Form ***************************/

jQuery(document).ready(function() {

    jQuery("#dropdown-filter").show();
    jQuery(".order-by-form").jqTransform();
    jQuery(".order-form").jqTransform();

	jQuery(".order-by-form .jqTransformSelectWrapper ul li a").click(function(){
		var index = jQuery(this).attr('index');
		var value = jQuery('.order-by-form select.jqTransformHidden option:eq('+index+')').attr('value');
		window.location.href=value;
	});
	
	jQuery(".order-form .jqTransformSelectWrapper ul li a").click(function(){
		var index = jQuery(this).attr('index');
		var value = jQuery('.order-form select.jqTransformHidden option:eq('+index+')').attr('value');
		window.location.href=value;
	});
	
});


/*************************** Marquee Width ***************************/

jQuery(window).load(function() {

	jQuery("#scroller-marquee").show();
	var socialWidth = jQuery("#social-icons").width();
	var scrollertitleWidth = jQuery("#scroller-title").width();
	
	if(socialWidth > 0) {
		jQuery("#scroller").css({"width" : 840 - socialWidth});
		jQuery("#scroller #scroller-marquee").css({"width" : 840 - socialWidth - scrollertitleWidth});
	} else {
		jQuery("#scroller").css({"width" : 920});
		jQuery("#scroller #scroller-marquee").css({"width" : 920 - scrollertitleWidth});	
	}
	
});


/*************************** Profile Details Height ***************************/

jQuery(document).ready(function(){

	var profiledetailsHeight = jQuery(".profile-details").height();
	if(profiledetailsHeight > 90) {
	jQuery(".profile-avatar").css({"height" : profiledetailsHeight});
	}
});


/*************************** Tabs ***************************/

jQuery(document).ready(function(){
	// We can use this object to reference the panels container
	var panelContainer = jQuery('div#panels');
	
	// Find panel names and create nav
	// -- Loop through each panel
	panelContainer.find('.panel').each(function(n){
		// For each panel, create a tab
		jQuery('div#review-links ul').append('<li class="tab"><a href="#' + (n+1) + '">' + jQuery(this).attr('id') + '</a></li>');
	});
	
	// Determine which tab should show first based on the URL hash	
	var panelLocation = location.hash.slice(1);
		if(panelLocation == '1'){
			var panelNum = panelLocation;
		} else if(panelLocation == '2'){
			var panelNum = panelLocation;
		} else if(panelLocation == '3'){
			var panelNum = panelLocation;
		} else if(panelLocation == '4'){
			var panelNum = panelLocation;
		} else if(panelLocation == '5'){
			var panelNum = panelLocation;
		} else if(panelLocation == '6'){
			var panelNum = panelLocation;
		} else if(panelLocation == '7'){
			var panelNum = panelLocation;
		} else if(panelLocation == '8'){
			var panelNum = panelLocation;			
		} else if(panelLocation == '9'){
			var panelNum = panelLocation;			
		} else if(panelLocation == '10'){
			var panelNum = panelLocation;
		}else{
			var panelNum = '1';
		}	
	// Hide all panels
	panelContainer.find('div.panel').hide();
	// Display the initial panel
	panelContainer.find('div.panel:nth-child(' + panelNum + ')').fadeIn('slow');
	// Change the class of the current tab
	jQuery('div#review-links ul').find('li.tab:nth-child(' + panelNum + ')').removeClass().addClass('tab-active');
	
	// What happens when a tab is clicked
	// -- Loop through each tab
	jQuery('div#review-links ul').find('li').each(function(n){
		// For each tab, add a 'click' action
		jQuery(this).click(function(){
			// Hide all panels
			panelContainer.find('div.panel').hide();
			// Find the required panel and display it
			panelContainer.find('div.panel:nth-child(' + (n+1) + ')').fadeIn('slow');
			// Give all tabs the 'tab' class
			jQuery(this).parent().find('li').removeClass().addClass('tab');
			// Give the clicked tab the 'tab-active' class
			jQuery(this).removeClass().addClass('tab-active');
		});
	});
});


/*************************** Gallery Shortcode Lightbox Support ***************************/

jQuery(document).ready(function(){

	jQuery("div.gallery-item .gallery-icon a").attr("rel", "prettyPhoto[gallery]");

});


/*************************** Lightbox ***************************/

function gp_lightbox() {

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

}

jQuery(document).ready(function(){
	gp_lightbox();
});


/*************************** Lightbox Image Hover ***************************/

function gp_image_hover() {

	jQuery('.overlay, div.gallery-item .gallery-icon').hover(
		function() {
			jQuery(this).find("a[rel^='prettyPhoto'] img").stop().fadeTo(750, 0.5);
		},
		function() {
			jQuery(this).find("a[rel^='prettyPhoto'] img").stop().fadeTo(750, 1);			
		}
	);
		
}

jQuery(document).ready(function(){
	gp_image_hover();
});


/*************************** Accordion ***************************/

jQuery(document).ready(function(){
	jQuery(".accordion").accordion({ header: "h3.accordion-title", autoHeight: false });
	jQuery("h3.accordion-title").toggle(function(){
		jQuery(this).addClass("active");
		}, function () {
		jQuery(this).removeClass("active");
	});	
});


/*************************** Tabs ***************************/

jQuery(document).ready(function(){
	jQuery(".sc-tabs").tabs({
		fx: {
			height:'toggle',
			duration:'fast'
		}
	});	
});


/*************************** Toggle Content ***************************/

jQuery(document).ready(function(){
	jQuery(".toggle-box").hide(); 
	
	jQuery(".toggle").toggle(function(){
		jQuery(this).addClass("toggle-active");
		}, function () {
		jQuery(this).removeClass("toggle-active");
	});
	
	jQuery(".toggle").click(function(){
		jQuery(this).next(".toggle-box").slideToggle();
	});
});


/*************************** Contact Form ***************************/

jQuery(document).ready(function(){
	
	jQuery('#contact-form').submit(function() {

		jQuery('.contact-error').remove();
		var hasError = false;
		jQuery('.requiredFieldContact').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				jQuery(this).addClass('input-error');
				hasError = true;
			} else if(jQuery(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
					jQuery(this).addClass('input-error');
					hasError = true;
				}
			}
		});
	
	});
				
	jQuery('#contact-form .contact-submit').click(function() {
		jQuery('.loader').css({display:"block"});
	});	

});
