jQuery(window).load(function() { 
	jQuery('.socialNetworkTwitter').show();
	if( jQuery('.socialNetworkHolder').length > 0) { jQuery('.socialNetworkHolder').tabs(); };
	if (jQuery.browser.webkit){ sameHeight(jQuery(".SameHeightHolder")); childSameHeight(jQuery(".childSameHeightHolder")); }
});
jQuery(document).ready(function() { 
	var $actionLink = jQuery('.sWebTheme_showSettings');
	$actionLink.click( function() {
		jQuery('.sWebTheme_Actions').slideToggle(300, changeText);
	});
	function changeText(){
		if(!jQuery('.sWebTheme_Actions').is(":visible")){
			$actionLink.text('Show Settings');
			$actionLink.removeClass('expandedSettings');
			createCookie("HomeOptionIsHidden", "true", 1);
		} else {
			$actionLink.text('Hide Settings');
			$actionLink.addClass('expandedSettings');
			eraseCookie("HomeOptionIsHidden");
		} 
	}
	if (!jQuery.browser.webkit){ sameHeight(jQuery(".SameHeightHolder")); childSameHeight(jQuery(".childSameHeightHolder")); }
	if ( $.browser.msie && jQuery(".sWebTheme_ActionsHolder:visible").length > 0 ){
		var calcWidth = 0;
		jQuery(".sWebTheme_ActionsHolder").children().each( function(){
			if( jQuery(this).hasClass("clear-both") ) return;
			calcWidth = calcWidth + jQuery(this).innerWidth() + parseInt(jQuery(this).css("margin-right")) + parseInt(jQuery(this).css("margin-left"));
		});
		if ( calcWidth > jQuery(".sWebTheme_Actions").width() ){
			jQuery(".sWebTheme_ActionsHolder").width(jQuery(".sWebTheme_Actions").width());
		} else {
			jQuery(".sWebTheme_ActionsHolder").width(calcWidth).css({"margin":"auto"});
		}
	}
});

function sameHeight(element){
	jQuery(element).each(function() {
		var height = 0;
		jQuery(".SameHeight", this).each(function() {
			var $this = jQuery(this);
			if ($this.height() > height) height = $this.height();
			
		}).css("height", height);
	});
}

function childSameHeight(element){
	jQuery(element).each(function() {
		var height = 0;
		jQuery(".childSameHeight", this).each(function() {
			var $this = jQuery(this);
			if ($this.height() > height) height = $this.height();
			
		}).css("height", height);
	});
}








//creating completed popup
jQuery(document).ready(function(){

	var warning = jQuery(".hasWarning");
	if ( warning.length > 0 ){
		warning.each(function(){
			var $this = jQuery(this);
			$this.css({"position":"relative", "z-index": 1});
			$this.append('<div class="callout"><img class="warningIcon" src="/DesktopModules/BSB/BSB.Content/ClientResources/images/skin-warning.png"/>'+
				'<div class="calloutText"><img class="warningIcon" src="/DesktopModules/BSB/BSB.Content/ClientResources/images/skin-warning.png"/> ' + 
				$this.attr("data-errorMessage") +
				' </div><b class="notch"></b></div>');
			$this.hoverIntent({ 
				sensitivity: 2, 
				interval: 100, 
				timeout: 100,
				over: function() { 
					var callOutPosition = jQuery(this).find(".calloutText").width() / 2;
					jQuery(this).css({"z-index": 999});
					jQuery(this).find("img.warningIcon").hide($.browser.msie? "fast" : "slow");
					jQuery(this).find(".calloutText").show($.browser.msie? "fast" : "slow");
					jQuery(this).find(".callout").animate({"top": "-36px", "right" : "-" + callOutPosition + "px" });
				},  
				out: function() { 
					jQuery(this).find("img.warningIcon").show("fast" );
					jQuery(this).find(".calloutText").hide("slow"); 
					jQuery(this).find(".callout").animate({"top": "-16px", "right" : "0px" });
					jQuery(this).css({"z-index": 1});
				} 
			});
		});
	}
	var skinStatusWrapper = jQuery(".skinStatus-Wrapper");
	if ( skinStatusWrapper.length > 0 ){
		var skinStatus = jQuery(".skinStatus");
		var dataStatus = ( skinStatus.attr("data-skin-status") / 100) * 24;
		skinStatus.css({"height": dataStatus + "px"});
        var isColorPopUp = false;
		skinStatusWrapper.hoverIntent({
			sensitivity: 2, 
			interval: 100, 
			timeout: 100,
			over: function() { 
                var skinStatusDetail = jQuery(".skinStatus-Detail", this);
                if(!isColorPopUp) {
                    jQuery(".skinStatus-Detail").css({"visibility":"hidden", "display":"block"});
                    if ( jQuery(".skinStatus-Detail").offset().left < 0 ){
                        jQuery(".skinStatus-Detail").css({"left":"0"});
                        jQuery(".skinStatus-CallOut").css({"left":"32px", "right": "auto"});
                    }
                    jQuery(".skinStatus-Detail").css({"visibility":"visible", "display":"none"});
                    jQuery(".skinStatus-Detail", this).slideToggle()
                    if (skinStatusDetail.attr('id') == 'color-Popup') {
                        isColorPopUp = true;
                    }
                } 
			},  
			out: function() {
                var skinStatusDetail = jQuery(".skinStatus-Detail", this);
                if (!isColorPopUp || skinStatusDetail.attr('id') !== 'color-Popup') {
                    skinStatusDetail.slideUp();
                    isColorPopUp = false;
                }
            }
		});

        jQuery(document).on('click', '.skCancelButton', function () {
            jQuery(this).closest('.skinStatus-Detail').slideUp();
            isColorPopUp = false; // Reset flag when cancel button is clicked
        });
	}

	var $actions = jQuery(".sWebTheme_ActionsLinks");
	var $ul = jQuery("<ul class='skinStatus-List' />");
	
	$actions.each(function(){
		var $this = jQuery(this);
		if($this.hasClass("actions_SettingLink") 
            || $this.hasClass("actions_AnnouncementLink")
            || $this.hasClass("actions_ModuleLink")
			|| $this.hasClass("actions_ThemeLink")
			|| $this.hasClass("actions_StatusLink") ) return this;
		var $li = jQuery("<li />");
		var $span = jQuery("<span class='skinStatus-Message' />");
		
		if( $this.hasClass("hasError")) {
			$li.addClass("skinStatus-Error");
			$span.text("Need Action!");
		}else if( $this.hasClass("hasWarning")) {
			$li.addClass("skinStatus-Warning");
			$span.text("Need Action!");
		}else{
			$li.addClass("skinStatus-Complete");
			$span.text("Complete");
		}
		
		var $a = jQuery("<a class='skinStatus-Link' />");
		$a.text( jQuery(">span", $this).text() ).attr("href", $this.attr("href"));
		$li.append($a);
		$li.append($span);
		$ul.append($li);
	});
	
	var $li = jQuery("<li class='floatClear' />");
	$ul.append($li);
	jQuery("h2.Modules").after($ul);
});
