var animatestart = true;
var animstartdelay = 4000;
var animtime = 2000; 

jQuery(window).load(function(){
	if (jQuery('#background_image img').length > 0) {
                        jQuery('#background_image img').css('width','1500px');
                        jQuery('#background_image img').css('left','-150px');
                        jQuery('#background_image img').css('top','-150px');
                        jQuery('#background_image img').css('opacity','0');
                        jQuery('#background_image').fadeIn(200);
			if (jQuery('#background_image').hasClass('bottom'))
	                        jQuery('#background_image img').css('top', '').stop().animate({width:970,bottom:0,left:0,opacity:1},animtime);
			else
				jQuery('#background_image img').animate({width:970,top:0,left:0,opacity:1},animtime);
	}
});

jQuery(document).ready(function(){

	var url = String(self.location);

	if (url.indexOf('#training') !== -1) {
		jQuery(".sidebar .menu li").removeClass("current-menu-item").removeClass("current_page_item");
		jQuery("#menu-item-246").addClass("current_page_item");
	}

	function isValidEmailAddress(emailAddress) {
    	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	    return pattern.test(emailAddress);
	}


    jQuery("form.contact-form").submit(function(){
	var datastr = 'send=Y';

	jQuery("input, textarea", this).each(function(){
	    if (jQuery.trim(jQuery(this).val()) === '' || (jQuery(this).hasClass('email') && ! isValidEmailAddress(jQuery.trim(jQuery(this).val())))) {
			jQuery(this).addClass("error");
	    } else {
			jQuery(this).removeClass("error");
			datastr += "&" + String(jQuery(this).attr('name')) + "=" + jQuery(this).val();
	    }
	})
	var s_form = this;
	if (jQuery(".error", this).length > 0) {
	    return false;
	} else {
	    var action = jQuery(this).attr("action");

		if (action.indexOf('#') == 0) {
			action = String(self.location) + action;
		}


	    var popupWindow = jQuery('<div class="thank_you"><a href="javascript:void(0)" class="close"></a></div>');
            jQuery.ajax({
	       type: "POST",
	        url: action,
		data: datastr,
		cache: false,
		success: function(data){popupWindow.dialog({modal: true, width: 600, height: 235, dialogClass: 'thankyou'});jQuery("input:text, textarea", s_form).val('');jQuery(".book-rev-edited").remove(); },
		error:function (xhr, ajaxOptions, thrownError){ alert('We are sorry, but something goes wrong. Please contact site admin.' + (xhr.statusText ? ' Error: ' + xhr.statusText : "")); }
	    });
	    jQuery(".thankyou .close, .ui-widget-overlay").live("click", function(){
		popupWindow.dialog("close");
	    })
	}

	return false;
    })

    jQuery(".book_free").click(function(e) {
	e.preventDefault();
	var popupWindow = jQuery(".book-rev");
	popupWindow.dialog({modal: true, width: 600, height: 600, dialogClass: 'book-rev-edited'});
	jQuery('body').addClass("booking");
	jQuery("#cont-vids").hide();

	jQuery(".book-rev-edited .close, .ui-widget-overlay").live("click", function(){
                popupWindow.dialog("close");
		jQuery("#cont-vids").show();
	})
    })

    jQuery(".menu-item-321 a").click(function(e){
	e.preventDefault();
	var popupWindow = jQuery('<div class="strategy"><a href="javascript:void(0)" class="close"></a></div>');
        var link = jQuery(this).attr('href');

	popupWindow.dialog({modal: true, width: 1000, height: 900, dialogClass: 'treatment01-edited'});
	popupWindow.load(link);
	jQuery("#cont-vids").hide();

        jQuery(".treatment01-edited .close, .ui-widget-overlay").live("click", function(){
                popupWindow.dialog("close");
		jQuery("#cont-vids").show();
        })

    })

    jQuery(".menu li a").each(function() {
	if (jQuery(this).attr("href") == "#" || true) {
	    var t_class = jQuery(this).attr("title");
	    if (t_class) {
		jQuery(this).addClass(t_class);
		jQuery(this).parent('li').addClass(t_class);
	    }
	}
    })

// loading effect for threatment strategy popup
	function loading_hide(loading) {
		loading.hide();
        jQuery(".strategy .contInner").removeClass('loading');
	}

//load text for threatment strategy popup
    function load_text(where, link) {
	var content = jQuery(".strategy .cont");
        var href = jQuery(link).attr("href");

	if (jQuery('.loading_box', content).length == 0) {
	    jQuery(content).append("<div class='loading_box'></div>");
	}
	var loading = jQuery('.loading_box',content);
	jQuery(".strategy .contInner").addClass('loading');
	loading.show();

	if (jQuery.trim(href) !== '' && jQuery.trim(href) !== '#') {
		jQuery(where).load(href + " .page .entry-content", function() {
		    loading_hide(loading);
		});
	} else {
		loading_hide(loading);
	}
        var ul = jQuery(link).parent('li').parent('ul');
        jQuery('li', ul).removeClass('active');
        jQuery(link).parent('li').addClass('active');
    }


// top menu strategy
    jQuery(".threat_menu a").live('click', function(e) {
	e.preventDefault();
	load_text(".strategy .contInner", this);
    })

// left menu strategy
    jQuery(".strategy .menu2 a").live('click', function(e) {
        e.preventDefault();
	load_text(".strategy .contInner .txt", this);
    })

// sub menu strategy
    jQuery(".strategy .menu3 a").live('click', function(e) {
        e.preventDefault();
        load_text(".strategy .contInner .txt .txt2", this);

    })

// google search

	jQuery(".gsc-search-button").live('click', function(){
		if (jQuery("input.gsc-input").val() !== '') jQuery(".gsc-clear-button").addClass("visible");
	});

	jQuery(".gsc-clear-button").live('click', function(){
		jQuery(this).removeClass("visible");
	});


})

