﻿// THESE FUNCTIONS ARE INCLUDED IN THE HEADER, AND ARE 
jQuery.pureology.endQueue = []

trace = function (msg,sel) {
	if(sel==undefined) sel=".footerlinks";
	jQuery(function(){
		jQuery(sel).after("<div style='background-color:#FFFFEA;border:1px solid #000;margin-bottom:10px;padding:10px;color:#000'>"+msg+"</div>");	
	})
	return msg;
}

endCall = jQuery.pureology.endCall = function(runMe) {
	jQuery.pureology.endQueue.push(runMe);
}

run = jQuery.pureology.quickRun = function(runMe) {
	if( jQuery.browser.safari ){ 
		if (jQuery('.x_chk').width() > 1 || jQuery('.x_chk').width() == null) {
			setTimeout(function(){run(runMe);runMe=null;},10);
			return false;
		} 
	};
	runMe();	
}

// GET QSTRING PARAMS and return results if present
// http://www.netlobo.com/url_query_string_javascript.html
jQuery.pureology.gup = function (name){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec(window.location.href);
	
	if( results == null ) return "";
	else return results[1];
}

/* ==== <quickRun Functions> ==== */
jQuery.pureology.showFooter = function() {
	jQuery('.connect').show();
}

jQuery.pureology.showAwards = function() {
	if (jQuery('.horz_overlay_content > img').size() > 0) {
		jQuery(".badge").show();
	}
}

jQuery.pureology.consultation = function() {
	chkUrlValues();
	jQuery('.con_'+stp).show();
}

jQuery.pureology.jsHide = function() {
	jQuery('.js_hide').hide();
}

jQuery.pureology.techPanes = function() {
if (!jQuery.pureology.pageEdit) {
	var active = document.location.toString().split('#')[1] || 0;
	jQuery('.panel_tech').before('<div class="tab_tech"><ul><li><a class="l_0" href="#"><span></span></a></li><li><a class="l_1" href="#"><span></span></a></li><li><a class="l_2" href="#"><span></span></a></li></ul></div>');
	jQuery('.tab_tech').find('a').each(function(i) {
		jQuery(this).find('span').html(jQuery('.x_'+i).find('h2:first').html()); 
		jQuery('.x_'+i).addClass('fntfx').find('h2:first').andSelf().hide();
		jQuery(this).click(function() {
			if (i > 0) {
				asrc = '/Images/btn_view_all_styling.png';
				ahref = '/education/techniques/styling-finishing';
			} else {
				asrc = '/Images/btn_view_other_cut_tech.png';
				ahref = '/education/techniques/cutting';
			}
			jQuery('.other_tech').stop(true).animate({opacity:0},'fast',function() { 
				jQuery('.other_tech img').attr('src', asrc);
				jQuery('.other_tech a').attr('href', ahref);
				jQuery('.other_tech').animate({opacity:1});
			});
			jQuery('.x_'+active).fadeOut('fast', function() {
				for (x=0;x<3;x++) {
					jQuery('.x_'+x).hide();
					jQuery('.l_'+x).removeClass('active');
				}
				jQuery('.x_'+i).fadeIn('fast');
				jQuery('.l_'+i).addClass('active');
			});
			active = i;
			return false;
		});
	});
	jQuery('.tab_tech').css('display','block');
	jQuery('.l_'+active).click();
	jQuery('.other_tech').show();
}
};
	
	
	
jQuery.pureology.dupNewsPagination = function() {
	if (jQuery('.sf_pager').length)
	var pager = "<div style='margin-bottom:35px;padding-left:0px;'><ol class='sf_pager'>"+jQuery('.sf_pager').html()+"</ol></div>";
	jQuery('.sf_newsList').before(pager);
}

/* ==== </quickRun Functions> ==== */

jQuery.pureology.searchDistBinder = function($) {
    $(".x_distSel").each(function() {
        $(this).change(function() {
            if ($(this).val() != "") {
                $.panther.jcall('distGetPublic', [$(this).val()], $.pureology.frm); //, $.panther.nlOpts
            }
            return false;
        });
    });
    $(".x_distBtn").click(function() {
        if ($("#distrib_state").val() == "") {
            alert('Please select a state.');
        } else {
            $.panther.jcall('distGetPublic', [$("#distrib_state").val()], $.pureology.frm);
        }
        return false;
    });
}

jQuery.pureology.searchBlockBinder = function($){
    $.pureology.fs=[];
   $("#zip")
     .focus(function(){
        if ($("#city").val() != "") $.pureology.city=$("#city").val();$("#city").val("");     
        if ($("#address").val() != "") $.pureology.address=$("#address").val();$("#address").val("");     
        $("#zip").val($.pureology.fs['zip']);
        this.select();
      }).blur(function(){
        $.pureology.fs[this.id]=$(this).val();
      });      

    $("#address,#city")
     .focus(function(){
        if ($("#zip").val() != "") $.pureology.fs['zip']=$("#zip").val();$("#zip").val("");
        $("#address").val($.pureology.fs['address']);
        $("#city").val($.pureology.fs['city']);   
        this.select();
      }).blur(function(){
        $.pureology.fs[this.id]=$(this).val();
      });

	$('#address,#city,#zip').keyup(function(event){getFormat(this,event,'cleanQ')});
    $(".x_findSalon").click(function(){
        if ($("#zip").val()!=""){
         document.location="/locator/searchResults.aspx?address="+$("#zip").val();
        } else {
        query=$("#address").val()+" "+$("#city").val();
        if ($("#state").val()!="") query+=","+$("#state").val();
        document.location = "/locator/searchResults.aspx?address=" + URLEncode(query.trim());
        }
        if(this.blur)this.blur();
        return false; 
    })
    
    $("#findSalon").submitOnEnter(function(){$(".x_findSalon").click()});
};

jQuery.pureology.noResults = function($) {
    $(".topTitle").html("SORRY, NO RESULTS FOUND.");
    $("#map").hide();
    $(".salon_results").hide();
    $(".locator_form").fadeIn();
    $(".salon_error").fadeIn();
    setTimeout("jQuery('#zip').focus()",200);
};

// SYSTEMS
jQuery.pureology.viewAllProducts = function() {
	jQuery('.main').css('overflow', 'visible');
	jQuery('.va_products').css({'position':'absolute', 'bottom':183+'px', 'overflow':'hidden', 'z-index':99}).prepend('<a href="#" class="va_toggle up">Close</a>');
	
	jQuery('.va_toggle').click(function(){
		products=jQuery('.va_products');
		if (parseInt(products.css('bottom')) > 0) {
			products.css('z-index',101);
			products.animate({bottom:-products.outerHeight()+203+'px',duration:600});
		} else {
			products.animate({bottom:183+'px',duration:600},function(){products.css('z-index',99);});
		}
		return false;
	});
	return false;
};