//Swf Object
(function(A) { A.flashPlayerVersion = function() { var D, B = null, I = false, H = "ShockwaveFlash.ShockwaveFlash"; if (!(D = navigator.plugins["Shockwave Flash"])) { try { B = new ActiveXObject(H + ".7") } catch (G) { try { B = new ActiveXObject(H + ".6"); D = [6, 0, 21]; B.AllowScriptAccess = "always" } catch (F) { if (D && D[0] === 6) { I = true } } if (!I) { try { B = new ActiveXObject(H) } catch (E) { D = "X 0,0,0" } } } if (!I && B) { try { D = B.GetVariable("$version") } catch (C) { } } } else { D = D.description } D = D.match(/^[A-Za-z\s]*?(\d+)(\.|,)(\d+)(\s+r|,)(\d+)/); return [D[1] * 1, D[3] * 1, D[5] * 1] } (); A.flashExpressInstaller = "expressInstall.swf"; A.hasFlashPlayer = (A.flashPlayerVersion[0] !== 0); A.hasFlashPlayerVersion = function(C) { var B = A.flashPlayerVersion; C = (/string|integer/.test(typeof C)) ? C.toString().split(".") : C; return (C) ? (B[0] >= (C.major || C[0] || B[0]) && B[1] >= (C.minor || C[1] || B[1]) && B[2] >= (C.release || C[2] || B[2])) : (B[0] !== 0) }; A.flash = function(M) { if (!A.hasFlashPlayer) { return false } var C = M.swf || "", K = M.params || {}, E = document.createElement("body"), B, L, H, D, J, I, G, F; M.height = M.height || 180; M.width = M.width || 320; if (M.hasVersion && !A.hasFlashPlayerVersion(M.hasVersion)) { A.extend(M, { id: "SWFObjectExprInst", height: Math.max(M.height, 137), width: Math.max(M.width, 214) }); C = M.expressInstaller || A.flashExpressInstaller; K = { flashvars: { MMredirectURL: window.location.href, MMplayerType: (A.browser.msie && A.browser.win) ? "ActiveX" : "PlugIn", MMdoctitle: document.title.slice(0, 47) + " - Flash Player Installation"}} } if (M.flashvars && typeof K === "object") { A.extend(K, { flashvars: M.flashvars }) } for (J in (I = ["swf", "expressInstall", "hasVersion", "params", "flashvars"])) { delete M[I[J]] } B = []; for (J in M) { if (typeof M[J] === "object") { L = []; for (I in M[J]) { L.push(I.replace(/([A-Z])/, "-$1").toLowerCase() + ":" + M[J][I] + ";") } M[J] = L.join("") } B.push(J + '="' + M[J] + '"') } M = B.join(" "); if (typeof K === "object") { B = []; for (J in K) { if (typeof K[J] === "object") { L = []; for (I in K[J]) { if (typeof K[J][I] === "object") { H = []; for (G in K[J][I]) { if (typeof K[J][I][G] === "object") { D = []; for (F in K[J][I][G]) { D.push(F.replace(/([A-Z])/, "-$1").toLowerCase() + ":" + K[J][I][G][F] + ";") } K[J][I][G] = D.join("") } H.push(G + "{" + K[J][I][G] + "}") } K[J][I] = H.join("") } L.push(window.escape(I) + "=" + window.escape(K[J][I])) } K[J] = L.join("&amp;") } B.push('<PARAM NAME="' + J + '" VALUE="' + K[J] + '">') } K = B.join("") } if (!(/style=/.test(M))) { M += ' style="vertical-align:text-top;"' } if (!(/style=(.*?)vertical-align/.test(M))) { M = M.replace(/style="/, 'style="vertical-align:text-top;') } if (A.browser.msie) { M += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'; K = '<PARAM NAME="movie" VALUE="' + C + '">' + K } else { M += ' type="application/x-shockwave-flash" data="' + C + '"' } E.innerHTML = "<OBJECT " + M + ">" + K + "</OBJECT>"; return A(E.firstChild) }; A.fn.flash = function(C) { if (!A.hasFlashPlayer) { return this } var B = 0, D; while ((D = this.eq(B++))[0]) { D.html(A.flash(A.extend({}, C))); if (D[0].firstChild.getAttribute("id") === "SWFObjectExprInst") { B = this.length } } return this } } (jQuery));
//End SwfObject

$(document).ready(function () {
    browser();
    //checks flash player version and player itself for SIFR
    if (parseInt($.flashPlayerVersion) < 9 || $.hasFlashPlayer == false) { $('body').addClass('noSIFR'); }

    $("ul.nav li").hover(function () {
        $(this).addClass("active");
        $(this).children("a").addClass("active");
        $(this).children("ul").css("display", "block");
        $(this).children("div").css("display", "block");

    }, function () {
        $(this).removeClass("active");
        $(this).children("a").removeClass("active");
        $(this).children("ul").css("display", "none");
        $(this).children("div").css("display", "none");
    });

    $('.nav7 > ul > li:first').removeClass('navTopper').addClass('navTopperLeft');

    $(".btn-slide").click(function () {
        $(".closePortlet").css("display", "block");
        $(this).parent().next("div").slideToggle("slow");
        $(this).toggleClass("active");

        return false;
    });

    $(".closePortlet").click(function () {
        $(".btn-slide").parent().next("div").slideUp("slow");
        $(".btn-slide").removeClass("active");
        $(".closePortlet").css("display", "none");
    });

    var $pp = $("a[rel^='pp']");
    var $hasPp = $pp.length

    if ($hasPp) {
        $pp.prettyPhoto({
            show_title: false,
            theme: 'light_square',
            opacity: 0.50
        });
    }

    var $ppAlt = $("a[rel^='ppAlt']");
    var $hasPpAlt = $ppAlt.length

    if ($hasPpAlt) {
        $ppAlt.prettyPhoto({
            show_title: false,
            theme: 'light_square_original',
            opacity: 0.50
        });
    }


    //this swaps out the text hints from the input boxes
    function switchText() {
        if ($(this).val() == $(this).attr('title'))
            $(this).val('').removeClass('inactive');
        else if ($.trim($(this).val()) == '')
            $(this).addClass('inactive').val($(this).attr('title'));
    }

    $('input[type=text][title!=""]').each(function () {
        if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
        if ($(this).val() == $(this).attr('title')) $(this).addClass('inactive');
    }).focus(switchText).blur(switchText);

    $('form').submit(function () {
        $(this).find('input[type=text][title!=""]').each(function () {
            if ($(this).val() == $(this).attr('title')) $(this).val('');
        });
    });

    var jsnews = $('#js-news');

    if (jsnews.length) {
        var newsLi = jsnews.children('li');
        newsLi.eq(0).addClass('active');

        var cycleTimer = {};
        function timer() {
            cycleTimer = $.timer(5000, function () {
                if (jsnews.children('li:last').hasClass('active')) {
                    $('li.active', jsnews).removeClass('active');
                    newsLi.eq(0).addClass('active');
                } else {
                    $('li.active', jsnews).removeClass('active').next().addClass('active');
                }
                timer();
            });
        }
        timer();
        $('#prev').click(function () {
            $.clearTimer(cycleTimer);
            if (jsnews.children('li:first').hasClass('active')) {
                $('li.active', jsnews).removeClass('active');
                jsnews.children('li:last').addClass('active');
            } else {
                $('li.active', jsnews).removeClass('active').prev().addClass('active');
            }

            return false;
        });

        $('#next').click(function () {
            $.clearTimer(cycleTimer);
            if (jsnews.children('li:last').hasClass('active')) {
                $('li.active', jsnews).removeClass('active');
                jsnews.children('li:first').addClass('active');
            } else {
                $('li.active', jsnews).removeClass('active').next().addClass('active');
            }
            return false;
        });
    }

    var slideShow = $('.slideShow');

    if (slideShow.length) {
        $('.slideShow').cycle({
            timeout: 6000,
            pager: '#nav',
            allowPagerClickBubble: true,
            pagerEvent: 'mouseover',
            pauseOnPagerHover: true,
            pagerAnchorBuilder: function (idx, slide) {
                return '#nav li:eq(' + idx + ') a';
            },
            autostop: 1,
            end: function () {
                $('.slideShow').cycle({ startingSlide: 0 });
                $('.slideShow').cycle('pause');
            }
        });
    }

    // Tabs
    var $tabs = $('ul.tabs');

    if ($tabs.length) {
        $tabs.tabs("div.panes > div");
    }

    // Show the selected models on change of the select menu
    var capacity = $('select.capacity');

    if (capacity.length) {
        capacity.bind("change", function (e) {
            var models = $(this).val();

            $(".models.selected").hide();

            if (models) {
                $("#" + models).show()
                               .addClass("selected");
            }
        });
    }

    var $processSteam = $("#processSteam");

    if ($processSteam.length) {
        // Initialize the Process Steam Configurator
        processSteamConfigurator.init($processSteam);
    }

    //Checks if portlet container has portlets in it
    var $portlets = $("#portlets > div").size();

    if ($portlets == 0)
        $("#portlets").hide();

});

jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};

(function($){$.browserTest=function(a,z){var u='unknown',x='X',m=function(r,h){for(var i=0;i<h.length;i=i+1){r=r.replace(h[i][0],h[i][1]);}return r;},c=function(i,a,b,c){var r={name:m((a.exec(i)||[u,u])[1],b)};r[r.name]=true;r.version=(c.exec(i)||[x,x,x,x])[3];if(r.name.match(/safari/)&&r.version>400){r.version='2.0';}if(r.name==='presto'){r.version=($.browser.version>9.27)?'futhark':'linear_b';}r.versionNumber=parseFloat(r.version,10)||0;r.versionX=(r.version!==x)?(r.version+'').substr(0,1):x;r.className=r.name+r.versionX;return r;};a=(a.match(/Opera|Navigator|Minefield|KHTML|Chrome/)?m(a,[[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,''],['Chrome Safari','Chrome'],['KHTML','Konqueror'],['Minefield','Firefox'],['Navigator','Netscape']]):a).toLowerCase();$.browser=$.extend((!z)?$.browser:{},c(a,/(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/,[],/(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));$.layout=c(a,/(gecko|konqueror|msie|opera|webkit)/,[['konqueror','khtml'],['msie','trident'],['opera','presto']],/(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);$.os={name:(/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase())||[u])[0].replace('sunos','solaris')};if(!z){$('html').addClass([$.os.name,$.browser.name,$.browser.className,$.layout.name,$.layout.className].join(' '));}};$.browserTest(navigator.userAgent);})(jQuery);
browser = function(){

            var OSName="Unknown OS";
            var browser = "";
            if (navigator.appVersion.indexOf("Mac")!=-1) OSName="Mac";
            if (navigator.appVersion.indexOf("Win")!=-1) OSName="PC";
            bodyClass = $.browser.className+OSName
            $("body").addClass(bodyClass);
}

function closeModal () {
    $.prettyPhoto.close();
}

var processSteamConfigurator = {
    /**
    * Initializes the Process Steam Configurator
    */
    init: function (scope) {
        var tabsApi = $("ul.tabs", scope).data("tabs");

        $("ul.tabs", scope).tabs(".pane");

        // Next button
        $(".next", scope).click(function (e) {
            e.preventDefault();

            tabsApi.next();
        });

        processSteamConfigurator.eventHandlers();
    },

	/**
	 * Removes illegal characters from a string
	 */
	removeIllegalCharacters : function (string) {
		return string.replace(/[^a-zA-Z0-9]/g, '');
	},

    /**
    * Handles the Event functionality of the Panes
    */
    eventHandlers: function () {
        var $processSteam = $("#processSteam"),
			$table = $("table", $processSteam),
			$button = $(".buttons a", $table),
			$yourCompleteSolution = $("#yourCompleteSolution", $processSteam);

        // Pane behavior
        $button.bind("click", function (e) {
            e.preventDefault();

			var $selections = $("#selections", $yourCompleteSolution),
				productName = $(this).attr("rel"),
				index = $(this).closest("td").index();

   			productName = processSteamConfigurator.removeIllegalCharacters(productName);

            // Display the template so jQuery can find it
            $(".selection", $processSteam).show();

            if ($(this).hasClass("selected")) {
                // Change the text for the top button
                $(this).closest("table")
					   .find("tbody td:eq(" + index + ") .buttons a span")
					   .text('Select');

                // Remove the class from the top button
                $(this).closest("table")
					   .find("tbody td:eq(" + index + ") .buttons a")
					   .removeClass("selected");

                // Change the text for the bottom button
                $(this).closest("table")
					   .find("tfoot td:eq(" + index + ") .buttons a span")
					   .text('Select');

                // Remove the class from the bottom button
                $(this).closest("table")
					   .find("tfoot td:eq(" + index + ") .buttons a")
					   .removeClass("selected");

                // If the button is de-selected, remove the info from the Your Complete Solution pane
                $("#product" + productName, $selections).remove();
            } else {
                // Change the text for the top button
                $(this).closest("table")
					   .find("tbody td:eq(" + index + ") .buttons a span")
					   .text('Selected');

                // Add the class to the top button
                $(this).closest("table")
					   .find("tbody td:eq(" + index + ") .buttons a")
					   .addClass("selected");

                // Change the text for the bottom button
                $(this).closest("table")
					   .find("tfoot td:eq(" + index + ") .buttons a span")
					   .text('Selected');

                // Add the class to the bottom button
                $(this).closest("table")
					   .find("tfoot td:eq(" + index + ") .buttons a")
					   .addClass("selected");

                // Copy the Title to the Your Complete Solution pane
                $(".completeTitle:first").text($(this).closest(".pane")
													  .find("h2")
													  .text());

                // Copy the Name to the Your Complete Solution pane
                $(".completeName:first").text($(this).closest("table")
													 .find("thead th:eq(" + index + ")")
													 .text()
													);
                // Copy the Image to the Your Complete Solution pane
                $(".completeImage:first").html($(this).closest("table")
													  .find("tbody td:eq(" + index + ") .image")
													  .clone()
													 );

                // Copy the Technical Specifications to the Your Complete Solution pane
                $(".completeTechnicalSpecifications:first").html($(this).closest("table")
																		.find("tbody td:eq(" + index + ") .technicalSpecifications")
																		.clone()
																	   );

				// Copy the Features to the Your Complete Solution pane
				var $features = $(this).closest("table")
								   .find("tbody td:eq(" + index + ") .features");

				if ( $features.length ) {
					$(".completeFeatures:first").html($(this).closest("table")
															 .find("tbody td:eq(" + index + ") .features")
															 .clone()
														    );
				}

                // Clone the row and append it to the list
                $(".selection:first", $selections).clone()
														.attr("id", "product" + productName)
														.removeClass("hide")
														.appendTo($selections);

				if ( !$features.length ) {
					$("#product" + productName).find(".columnThree").addClass("hide");
				}
            }

            // Hide the template so it's hidden from view
            $(".selection:first", $processSteam).hide();
        });

        // Print button
        var $yourCompleteSolutionPrint = $("#print a", $yourCompleteSolution);

        $yourCompleteSolutionPrint.bind("click", function (e) {
            e.preventDefault();

            window.print();
        });
    }
}

$(window).load(function(){
	// Define an equal height for all items in each row
	var $equalColumns = $(".equalColumns"),
		$equalColumns2 = $(".equalLandingColumns");

    if ($equalColumns.length) {
        $("div.row").each(function () {
            $(this).find('div.category').equalHeight();
        });
    }

    if ($equalColumns2.length) {
        $("div.row").each(function () {
            $(this).find('div.feature').equalHeight();
        });
    }
});
