﻿//~INIT
var $j = jQuery.noConflict();

//~COMMON FUNCTION LOAD
function preCommonInit(){
    
    //preLoadImage();
    initTopNavigation(); //header navigation dropdown
    addNavigationShadow(); //add navigation
    addHeaderShadow();//title shadow
    animateButton("body"); //buttons
    initBreadCrumb();//breadcrumb
    initFooter(); //footer
}
function preProducts(){
    productsIntrestedIn();
    productsFeature();
    productsFaq();
    animateProductMenu()
}
function preNonProducts(){
    animateProductMenu();
    productsFeature();
    productsFaq();
}

function debugTime(start,content){
    //if($j.browser.mozilla && start){console.time(content);}
    //else if($j.browser.mozilla){console.timeEnd(content);}
}

//~Products Features class
function productsFeature() {$j(document).ready(function(){
    debugTime(true,"productsFeature()");
    $j("#product-content-wrap .left-wrap .wrap-bg .feature ul li").each(function(){
        $j(this).wrapInner("<div></div>");
    });
    
    $j("#product-content-wrap .left-wrap .wrap-bg .feature ul").each(function(){
        $j(this).wrap("<div class=\"corners-wrap\"></div>")
            .before("<span class=\"topleft\"></span><span class=\"topright\"></span><span class=\"bottomleft\"></span><span class=\"bottomright\"></span>");
    });
    
    debugTime(false,"productsFeature()");
});}

//~Login Features class
function loginFeature() {$j(document).ready(function(){
    debugTime(true,"loginFeature()");
    $j("#product-content-wrap .login-rightbottom-wrap .feature ul li").each(function(){
        $j(this).wrapInner("<div></div>");
    });
    
    $j("#product-content-wrap .login-rightbottom-wrap .feature ul").each(function(){
        $j(this).wrap("<div class=\"corners-wrap\"></div>")
            .before("<span class=\"topleft\"></span><span class=\"topright\"></span><span class=\"bottomleft\"></span><span class=\"bottomright\"></span>");
    });
    
    debugTime(false,"loginFeature()");
});}

//~Login Features class
function customBullet(expression) {$j(document).ready(function(){
    debugTime(true,"customBullet()");
    $j(expression+" ul li").each(function(){
        $j(this).wrapInner("<div></div>");
    });
    
    $j(expression+" ul").each(function(){
        $j(this).wrap("<div class=\"corners-wrap\"></div>")
            .before("<span class=\"topleft\"></span><span class=\"topright\"></span><span class=\"bottomleft\"></span><span class=\"bottomright\"></span>");
    });
    
    debugTime(false,"customBullet()");
});}


//~Products FAQ class
function productsFaq() {$j(document).ready(function(){
    debugTime(true,"productsFaq()");
    var t_id = 1;
    $j("#product-content-wrap .left-wrap .wrap-bg .faq ul li").each(function(){
        $j(this).attr("id","faq-"+t_id).wrapInner("<p id=\"faq-"+t_id+"-p\" style=\"display:none;\"></p>").attr("class","hide");
        $j("#faq-"+t_id+ " b").insertBefore("#faq-"+t_id + " p").wrap("<a onclick=\"faqToggle('faq-"+t_id+"')\"></a>").after("<span class=\"hide\">Hide</span><span class=\"show\">Show</span>");
        t_id += 1;
    });
    $j("#product-content-wrap .left-wrap .wrap-bg .faq ul li:first-child").removeClass("hide").addClass("show")
    $j("#product-content-wrap .left-wrap .wrap-bg .faq ul li:first-child p").css("display","inline-block");
    debugTime(false,"productsFaq()");
});}


//~Products FAQ toggle hide/show
function faqToggle(id) {$j(document).ready(function(){
    $j("#"+id+"-p").slideToggle({queue:false, duration:400, easing:"swing", complete:function(){
        if($j("#"+id).hasClass("hide")){
            $j("#"+id+"-p").attr("style","display:none");
        }
    } });
    if($j("#"+id).hasClass("hide")) {
        $j("#"+id).removeClass("hide").addClass("show");
    }
    else {
        $j("#"+id).addClass("hide").removeClass("show");
    }
});}


//~Products each page add a cross link title
function productsIntrestedIn() {$j(document).ready(function(){
    debugTime(true,"productsIntrestedIn()");
    $j("#product-content-wrap .left-wrap .wrap-bg").each(function(){
        $j(this).append("<span class=\"cross-link-title\">You may also be interested in:</span>");
    });
    
    debugTime(false,"productsIntrestedIn()");
});}

//~Products clear sub tab
function clearSubTab() {$j(document).ready(function(){
    $j("#sub-tabs div a:first-child").attr("onclick","");
});}

//~Add shadow to header title & header image function
function addHeaderShadow() {$j(document).ready(function(){
    debugTime(true,"topHeaderShadow()");
    var title;
    var shortTitle;
    $j("#product-header-wrap .left-wrap .title").each(function(){
        if($j(this).hasClass("title-image")) {
            title = $j(this).text();
            shortTitle = $j(this).html().replace(/ /g, "").replace(/&nbsp;/, "");
            //$debug("src=\"../../image/products/logo/"+shortTitle+".jpg\" ");
            $j(this).html("<img src=\"image/products/logo/"+shortTitle+".jpg\" alt=\""+title+"\" onerror=\"headerImageError('"+title+"')\" />");
        }
        else {
            $j(this).prepend("<span class=\"shadow\">"+$j(this).html()+"</span>");
        }
        $j("#product-toc").load("toc/undefined-toc.html");
        $j("#product-toc").load("toc/"+shortTitle+"-toc.html");
        
        //$debug("../toc/"+shortTitle.toLowerCase()+"-toc.html");
    });
    
    debugTime(false,"topHeaderShadow()");
});}
function headerImageError(title) {$j(document).ready(function(){
    $j("#product-header-wrap .left-wrap .title").each(function(){
        $j(this).html(title).prepend("<span class=\"shadow\">"+$j(this).html()+"</span>");
    });
});}

//~TOP HEADER - DROPDOWN MENU - for header-~.html
function addNavigationShadow() {$j(document).ready(function(){
    debugTime(true,"addNavigationShadow()");
    $j("#navigation-tabs #sub-tabs ul li:first-child").prepend("<span class=\"top-shadow\"></span>");
    $j("#navigation-tabs #sub-tabs ul li:last-child").prepend("<span class=\"bottom-shadow\"></span>");
    $j("#navigation-tabs #sub-tabs ul li").prepend("<span class=\"left-shadow\"></span><span class=\"right-shadow\"></span>");
    //add arrow to navigation
    $j("#navigation-tabs #sub-tabs .arrow").prepend("<span class=\"img\"></span>");
    $j("#navigation-tabs #sub-tabs .right-arrow").prepend("<span class=\"img\"></span>");
    debugTime(false,"addNavigationShadow()");
});}

function addDropDown(id){
$j(document).ready(function(){
    $j("#tab-dropdown-"+id).attr("onmouseover","");
    $j("#tab-dropdown-"+id).attr("onmouseout","");
    $j("#tab-dropdown-"+id).hover(
	    function(){
	        $j("#tab-dropdown-"+id+"-ul").stop();
            $j("#tab-dropdown-"+id+"-ul").show();
            

            //check for which type/level of ul
            if($j("#tab-dropdown-"+id+"-ul").hasClass("s-down")){
                $j("#tab-dropdown-"+id+"-ul")
                    .css("top","27px")
                    .css("z-index","10")
                    .animate({"opacity": "1","top": "32px"}, { queue:false, duration:300,complete:function (){$j("#tab-dropdown-"+id+"-ul").css("opacity","inherit");}});
            }
            else { //for inner menu
                $j("#tab-dropdown-"+id+"-ul").animate( {"opacity": "1"}, {queue:false,duration:300,complete:function (){$j("#tab-dropdown-"+id+"-ul").css("opacity","inherit");}} );
            }
	        
	        //setting for parent dropdown
	        $j("#tab-dropdown-"+id+"-a").addClass('tab-dropdown-hover', 300);
	    },
	    function(){
            if($j("#tab-dropdown-"+id+"-ul").hasClass("s-down")){
                $j("#tab-dropdown-"+id+"-ul").animate({"opacity": "0","top": "27px"}, {queue:false, duration:300,
                    complete:function (){
                        if(!$j("#tab-dropdown-"+id+"-a").hasClass("tab-dropdown-hover")){
                            $j("#tab-dropdown-"+id+"-ul").hide();
                        }
                    }
                });                             
            }
            else {
                $j("#tab-dropdown-"+id+"-ul").animate({"opacity": "0"}, {queue:false, duration:300,
                    complete:function (){
                        if(!$j("#tab-dropdown-"+id+"-a").hasClass("tab-dropdown-hover")){
                            $j("#tab-dropdown-"+id+"-ul").hide();
                        }
                    }
                });  
            }

            //setting for parent dropdown
            $j("#tab-dropdown-"+id+"-a").removeClass('tab-dropdown-hover', 300);
	    } 
    );
});}


//~END

//~FOOTER TOGGLE
var isFooterExpand = false;

function footerClick() {$j(document).ready(function(){
    
    if(isFooterExpand){
        $j("#sitemap").slideUp( { queue:false, duration:500, easing:'swing' , complete:function(){$j.scrollTo( '100%', 500 );} });
        isFooterExpand=false;
    }
    else{
        //$debug("open "+$j("#sitemap").height() + 'px');
        $j("#sitemap").slideDown( { queue:false, duration:500, complete:function(){
                $j.scrollTo( '100%', 500 );
            }
        });
        //$j("#sitemap").css("height","0px");
        //$j("#sitemap").animate({"height": newHeight}, { queue:false, duration:900 } );
        //setTimeout(function(){window.location='#bottom'}, 500);
        
        //$j.scrollTo( '#footer-wrapper', {queue:false, duration:500, easing:'easeOutElastic'} );
        isFooterExpand=true;
    }
});}


function openFooter() {$j(document).ready(function(){

    if(!isFooterExpand){
        //$debug("open "+$j("#sitemap").height() + 'px');
        $j.scrollTo( '100%', 500 );
        footerAll(true);
        $j("#sitemap").slideDown( { queue:false, duration:500, complete:function(){
                $j.scrollTo( '100%', 500 );
            } 
        });
        //$j("#sitemap").css("height","0px");
        //$j("#sitemap").animate({"height": newHeight}, { queue:false, duration:900 } );
        //setTimeout(function(){window.location='#bottom'}, 500);
        
        //$j.scrollTo( '#footer-wrapper', {queue:false, duration:500, easing:'easeOutElastic'} );
        isFooterExpand=true;
    }

});}

var f_id = 1;
var f_id2 = 1;
function initFooter() {$j(document).ready(function(){
    $j("#sitemap .group").each(function(){
        $j(this).attr("id","footer-group-"+f_id);
        $j("#"+this.id+" .h3")
            .attr("id","footer-group-h3-"+f_id);
            //.attr("href","javascript:toggleFooter(\'footer-group-"+f_id+"\');");
        $j("#"+this.id+" .icon").attr("href","javascript:toggleFooter(\'footer-group-"+f_id+"\');");
        $j("#"+this.id).addClass("hide");
        f_id += 1;
    });
    //setting for each h4
    $j("#sitemap .group .h4").each(function(){
        $j(this).attr("id","footer-group-h4-"+f_id2).hide();
        f_id2+=1;
    });
    
    //setting the hover event to h4
    $j("#sitemap .group .h4").each(function(){
        $j(this).bind("mouseenter",
            function(){
                $j("#"+this.id).animate({"paddingLeft": "55px"}, { queue:false, easing:'swing', duration:100 } );
            }
        ).bind("mouseleave",
            function(){
                $j("#"+this.id).animate({"paddingLeft": "50px"}, { queue:false, easing:'swing', duration:100 } );
            }
        );
    });
    //setting the hover event to h3
    $j("#sitemap .group .h3").each(function(){
        $j(this).bind("mouseenter",
            function(){
                $j("#"+this.id).animate({"paddingLeft": "45px"}, { queue:false, easing:'swing', duration:100 } );
            }
        ).bind("mouseleave",
            function(){
                $j("#"+this.id).animate({"paddingLeft": "40px"}, { queue:false, easing:'swing', duration:100 } );
            }
        );
    });
    
    
});}

function animateSelectionBox(){animationSmallSlide("#box-selection-wrap .box-select-text");}
function animateProductMenu(){animationSmallSlide(".right-wrap .menu");}

function animationSmallSlide(expression) {$j(document).ready(function(){

    //setting the hover event to selection box on homepage
    $j(expression).each(function(){
        $j(this).bind("mouseenter",
            function(){
                $j("#"+this.id).animate({"paddingLeft": "5px"}, { queue:false, easing:'swing', duration:100 });
            }
        ).bind("mouseleave",
            function(){
                $j("#"+this.id).animate({"paddingLeft": "0px"}, { queue:false, easing:'swing', duration:100 });
            }
        );
    });
    
});}



function toggleFooter(id) {$j(document).ready(function(){
    //$debug($j("#"+id).hasClass("expand"));

    if($j("#"+id).hasClass("expand")){
        $j("#"+id+" .h4").each(function(){
            //$j(this).slideToggle( { queue:false, easing:'easeOutExpo', duration:500} );
            //$j(this).hide();
            $j(this).hide({ queue:true, duration:300,complete:function(){} });
        });
        $j("#"+id).removeClass("expand").addClass("hide");
        $j.scrollTo( '100%', 500 );
    }
    else{
        $j("#"+id+" .h4").each(function(){
            //$j(this).show();
            $j(this).show({ queue:true, duration:300,complete:function(){$j.scrollTo( "100%", 00 );} });
            //$j(this).animate({"opacity": "1"}, { queue:true, duration:300 });
            //$j(this).slideToggle( { queue:false, easing:'easeOutExpo', duration:500} );
        });
        $j("#"+id).addClass("expand").removeClass("hide");
        
    }
    
});}

function footerAll(toShow) {$j(document).ready(function(){
    if(toShow) {
        $j("#sitemap .group").addClass("expand");
        $j("#sitemap .group .h4").show({ queue:true, duration:300,complete:function(){$j.scrollTo( "100%", 00 );} });
    }
    else {
        $j("#sitemap .group").removeClass("expand");
        $j("#sitemap .group .h4").hide({ queue:true, duration:300 });
    }
});}
//~END

//~RECOMMENDATION TOGGLE - for Residential.aspx,Business.aspx
var selector = "s1";
function toggleMenu(id) {$j(document).ready(function(){
    $j("#left-selector").removeClass(selector);
    $j("#left-selector").addClass(id);
    
    $j("#box-content-"+selector).addClass("hide");
    $j("#box-content-"+id).removeClass("hide");
    
    selector=id;
});}
//~END

//~ACCORDION FOR MAIN PAGE - for Residential.aspx,Business.aspx
function onAccordion() {$j(document).ready(function(){
    $j("#accordion").accordion({
        event: 'mouseover',
        animated: 'easeslide',
        alwaysOpen: true,
        fillSpace: false,
        header: "h3"
    });
});}
//~END



//~UNIVERSAL MOUSEOVER BUTTON EVENT
function animateButton(context){

    $j(document).ready(function () {
        debugTime(true, "animateButton(" + context + ")");
        var bh_expression = ".btnover span:first-child";
        var bh_expression_2 = ".btnover-2";

        // before having sub span
        $j(bh_expression_2, context)
        .each(function () {
            $j(this)
            .prepend("<span style=\"" + $j(this).attr("style") + "\"></span>")
            .addClass("btnover").removeClass("btnover-2");
        });

        if ($j.browser.msie) {
            $j(bh_expression, context)
            .css("opacity", "1")
            .css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../image/appstore/1pixel.png', sizingMethod='scale')")
            .each(function () {
                try {
                    var bpos = $j(this).css("backgroundPosition");
                    var pos = bpos.split(" ");
                    $j(this).css("background-position", "left " + pos[1]);
                }
                catch (e) {}
            })
            .bind("mouseenter", function () {
                var bpos = $j(this).css("backgroundPosition");
                var pos = bpos.split(" ");
                $j(this).css("background-position", "center " + pos[1]);
            })
            .bind("mouseleave", function () {
                var bpos = $j(this).css("backgroundPosition");
                var pos = bpos.split(" ");
                $j(this).css("background-position", "left " + pos[1]);
            })
            .bind("mousedown", function () {
                var bpos = $j(this).css("backgroundPosition");
                var pos = bpos.split(" ");
                $j(this).css("background-position", "right " + pos[1]);
            });
        }
        else {
            $j(bh_expression, context)
            .css("opacity", "0")
            .each(function () {
                var bpos = $j(this).css("background-position");
                var pos = bpos.split(" ");
                $j(this).css("background-position", "center " + pos[1]);
            })
            .bind("mouseenter", function () {
                $j(this).animate({ "opacity": "1" }, { queue: false, duration: 250 });
            })
            .bind("mouseleave", function () {
                var bpos = $j(this).css("background-position");
                var pos = bpos.split(" ");
                $j(this)
                    .animate({ "opacity": "0" }, { queue: false, duration: 250 })
                    .css("background-position", "center " + pos[1]);
            })
            .bind("mousedown", function () {
                bpos = $j(this).css("background-position");
                pos = bpos.split(" ");
                $j(this).css("background-position", "right " + pos[1]);
            });
        }
        debugTime(false, "animateButton(" + context + ")");
    });
}
//~END



//~UNIVERSAL BREADCRUMB EFFECT
function initBreadCrumb() {$j(document).ready(function(){
    var zindex = 20;
    preInit("breadcrumb");
    preInit("breadcrumb-current");
    
    function preInit(classId){
        debugTime(true,"initBreadCrumb()("+classId+")");
        $j("."+classId).each(function(){
            $j(this).css("z-index", zindex);
            zindex-=1;
        });
    
//        $j("."+classId+" a")
//        .bind("mouseenter", function(){
//            var effectStyle = "38px";
//            var effectStyleFirst = "48px";
//            
//            if($j("#"+this.id).hasClass("first")) {
//                effectStyle = effectStyleFirst;
//            }
//            $j("#"+this.id).animate({"paddingLeft": effectStyle,"paddingRight": "28px"}, { queue:false, easing:'easeOutBounce', duration:700 } );

//        })
//        .bind("mouseleave", function(){
//            var effectStyle = "30px";
//            var effectStyleFirst = "40px";
//            
//            if($j("#"+this.id).hasClass("first")) {
//                effectStyle = effectStyleFirst;
//            }
//            $j("#"+this.id).animate({"paddingLeft": effectStyle,"paddingRight": "20px"}, { queue:false, easing:'easeOutBounce', duration:700 } );
//        });
        
        $j("."+classId+" a").bind("mouseenter",
            function(){
                var effectStyle = "padding-left:38px;padding-right:28px;";
                var effectStyleFirst = "padding-left:48px;padding-right:28px;";
                
                if($j("#"+this.id).hasClass("first")) {
                    effectStyle = effectStyleFirst;
                }
                new Effect.Morph(this.id, {
                    style: effectStyle,
                    transition: Effect.Transitions.spring,
                    duration: 0.35
                });
            })
        .bind("mouseleave",
            function(){
                var effectStyle = "padding-left:30px;padding-right:20px;";
                var effectStyleFirst = "padding-left:40px;padding-right:20px;";
                
                if($j("#"+this.id).hasClass("first")) {
                    effectStyle = effectStyleFirst;
                }
                new Effect.Morph(this.id, {
                    style: effectStyle,
                    transition: Effect.Transitions.spring,
                    duration: 0.35
                });
            });
        debugTime(false,"initBreadCrumb()("+classId+")");
    }
});}
//~END



//~UNIVERSAL HEADER MENU EFFECT
function initTopNavigation() {$j(document).ready(function(){
    preInit();
    function preInit(){
        debugTime(false,"initTopNavigation()");
        $j("#main-tabs .effect-wrap").bind("mouseenter",function(){
            var effectStyle = "height:35px;";
            //$j("#"+this.id+"-bg").animate({"height": "35px"}, { queue:false, easing:'easeOutElastic', duration:300 } );
            new Effect.Morph(this.id+"-bg", {
                style: effectStyle,
                transition: Effect.Transitions.spring,
                duration: 0.35
            });
        })
        .bind("mouseleave",function(){
            var effectStyle = "height:30px;";
            //$j("#"+this.id+"-bg").animate({"height": "30px"}, { queue:false, easing:'easeOutElastic', duration:300 } );
            new Effect.Morph(this.id+"-bg", {
                style: effectStyle,
                transition: Effect.Transitions.spring,
                duration: 0.35
            });
        });
        debugTime(false,"initTopNavigation()");
    }
});}
//~END

//~SHOW POPUP
function animatePopup(child)
{$j(document).ready(function(){
    debugTime(true,"animatePopup("+""+")");
    
    if(child=="popup-talktous"){
        $j("#ttuframe").attr("src","talktous.aspx")
    }
    
    $j("#popup-wrapper").fadeIn( {queue:true, duration:300, easing:"swing", complete:function(){
        $j("#"+child).fadeIn( {queue:true, easing:"swing",duration:200} );
    }} );
    
    
    debugTime(false,"animatePopup("+""+")");
});}
function closePopup(child)
{$j(document).ready(function () {
    debugTime(true, "closePopup(" + "" + ")");

    $j("#" + child).fadeOut({ queue: true, duration: 200, easing: "swing", complete: function () {
        $j("#popup-wrapper").fadeOut({ queue: true, easing: "swing", duration: 300 });
    } 
    });

    if (child == "popup-workshop") { 
        
    }  

    debugTime(false, "closePopup(" + "" + ")");
});}

//~VERTICAL ACCORDION
function fixAccordionCorner(parent_id)
{$j(document).ready(function(){
    debugTime(true,"fixAccordionCorner("+parent_id+")");
    //FIX LEFT CORNER BACKGROUND WITH COLOR
    $j("#"+parent_id+" .accordion .header-top-bg .corner").css("background-color",$j("#"+parent_id).css("background-color"));
    $j("#"+parent_id+" .accordion .header-bottom-bg .corner").css("background-color",$j("#"+parent_id).css("background-color"));
    
    //EXTRA SAFE RIGHT
    $j("#"+parent_id+" .accordion .header-top-bg").css("background-color",$j("#"+parent_id).css("background-color"));
    $j("#"+parent_id+" .accordion .header-bottom-bg").css("background-color",$j("#"+parent_id).css("background-color"));
    debugTime(false,"fixAccordionCorner("+parent_id+")");
});}

function initAccordion2(parent_id,start_id,rowHeight,component_class,is_fixed)
{$j(document).ready(function(){
    debugTime(true,"initAccordion("+parent_id+","+start_id+")");
    var nl_ele = $j("#"+start_id);
    var nl_id = start_id
    var nl_lastblock = start_id;
    var foundLastBlock = false;
    var timer_01;
    
    fixAccordionCorner(parent_id);

    $j("#"+parent_id+" .accordion").bind("mouseenter",
        function(){
            var id = this.id;
            if(this!=nl_ele)
            {
                var tempHeight = 0;
                var isLast = false;
                
                $j("#"+id+" ."+component_class).each(function(){tempHeight += rowHeight;});
                
                $j("#"+nl_id+" .ac-content").animate({height: 0+"px"}, { queue:false, easing:"easeOutCubic", duration:1000 });
                $j("#"+id+" .ac-content").animate({height: tempHeight+"px"}, { queue:false, easing:"easeOutCubic", duration:1000 });
                
                //CHECKING LASTBLOCK TO REMOVE BELOW PIXEL
                if($j("#"+id).hasClass("lastblock")&&(is_fixed==false)) {
                    if(foundLastBlock==false) { //check whether lastblock is already set.
                        nl_lastblock = id;
                    }
                    clearTimeout(timer_01); //clear any pending timer.
                    $j("#"+nl_lastblock).css("border-bottom", "solid 1px #c8c8c8");
                }
                else {
                    clearTimeout(timer_01); //clear any timer before creating a new one.
                    timer_01 = setTimeout(function(){
                        if($j("#"+id).hasClass("selected")){ //while timer end, check whether lastblock is selected.
                            $j("#"+nl_lastblock).css("border-bottom", "solid 0px #c8c8c8");
                        }
                    },950);
                }
                
                nl_id = this.id;
                nl_ele = this;
            }
        }
    );
    debugTime(false,"initAccordion("+parent_id+","+start_id+")");
});}

function initAccordion(parent_id,start_id)
{$j(document).ready(function(){
    debugTime(true,"initAccordion("+parent_id+","+start_id+")");
    var nl_ele = $j("#"+start_id);
    var nl_id = start_id
    var nl_lastblock = start_id;
    var foundLastBlock = false;
    var rowHeight = 77;
    var timer_01;
    
    fixAccordionCorner(parent_id);

    $j("#"+parent_id+" .accordion").bind("mouseenter",
        function(){
            var id = this.id;
            if(this!=nl_ele)
            {
                var tempHeight = 0;
                var isLast = false;
                
                $j("#"+id+" .para-row").each(function(){tempHeight += rowHeight;});
                
                $j("#"+nl_id+" .ac-content").animate({height: 0+"px"}, { queue:false, easing:"easeOutCubic", duration:1000 });
                $j("#"+id+" .ac-content").animate({height: tempHeight+"px"}, { queue:false, easing:"easeOutCubic", duration:1000 });
                
                //CHECKING LASTBLOCK TO REMOVE BELOW PIXEL
                if($j("#"+id).hasClass("lastblock")) {
                    if(foundLastBlock==false) { //check whether lastblock is already set.
                        nl_lastblock = id;
                    }
                    clearTimeout(timer_01); //clear any pending timer.
                    $j("#"+nl_lastblock).css("border-bottom", "solid 1px #c8c8c8");
                }
                else {
                    clearTimeout(timer_01); //clear any timer before creating a new one.
                    timer_01 = setTimeout(function(){
                        if($j("#"+id).hasClass("selected")){ //while timer end, check whether lastblock is selected.
                            $j("#"+nl_lastblock).css("border-bottom", "solid 0px #c8c8c8");
                        }
                    },950);
                }
                
                nl_id = this.id;
                nl_ele = this;
            }
        }
    );
    $j("#"+parent_id+" .accordion").each(function(){
        var id = this.id;

        var tempHeight = 0;
        var isLast = false;
        if($j("#"+id).hasClass("selected")) {
            $j("#"+id+" .para-row").each(function(){tempHeight += rowHeight;});
            $j("#"+id+" .ac-content").animate({height: tempHeight+"px"}, { queue:false, easing:"easeOutCubic", duration:1000 });
        }
    });
    debugTime(false,"initAccordion("+parent_id+","+start_id+")");
});}


//MOUSEHOVER CHANGE HEADER BG
function plMenuHover(parent_id, new_id)
{$j(document).ready(function(){
    var old_id=$j("#"+parent_id).attr("class");
    $j("#"+old_id).removeClass("selected");
    $j("#"+new_id).addClass("selected");
    $j("#"+parent_id)
        .removeClass(old_id)
        .addClass(new_id);
});}
//~END

//QUERYSTRING
function queryString($ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
        ft = gy[i].split("=");
        if (ft[0] == $ji) {
            return ft[1];
        }
    }
}
//~END

//QUERYSTRING
function sendAnEmail(id) {
    var gy = "mailto:&nbsp;?subject=Check out NexWave Telecoms&amp;body=Check out this site "+document.location.href;
    document.location.href=gy;
}
//~END


function setErrorMsg(txt,area,container) {$j(document).ready(function(){
    $j("#"+container).show();
    $j("#"+area).html(txt);
    $j("#"+area).focus();
});}


//~DEBUGGER SCRIPT
var debugLineNumber = 1;
function $get(id) {return document.getElementById(id);}
function $getDebugLine() {return "Line "+debugLineNumber+" : ";}
function $debug(value){
    $get("debugger").innerHTML+=$getDebugLine()+value+"<br/>";debugLineNumber+=1;
}
//~END

//~PRE LOAD CSS IMAGES
function preLoadImage() {
$j(document).ready(function(){
    $j.preloadCssImages();
});}
//~END

/*~FIXED IE CSS ERRORS
var path = document.location.href
//var homepath = path.substring(0,path.indexOf('/nexwavetelecoms/', 1)+1) + "nexwavetelecoms/";
var homepath=""; //LOCAL
//var homepath="http://nexwave.wanghe.sg/"; //ONLINE

window.onload = function() {
    if (document && document.getElementsByTagName) {
        var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
        var browserName=navigator.appName;
        var ver = getInternetExplorerVersion();
        if(browserName=="Microsoft Internet Explorer" && ver < 8.0 ) {
            var head = document.getElementsByTagName('head')[0];
            var link = document.createElement('link');
            link.type = 'text/css';
            link.rel = 'stylesheet';
            link.href = homepath+'css/invalid.css';
            head.appendChild(link);
        }
        else if(browserName=="Microsoft Internet Explorer" && ver == 8.0 ) {
            var head = document.getElementsByTagName('head')[0];
            var link = document.createElement('link');
            link.type = 'text/css';
            link.rel = 'stylesheet';
            link.href = homepath+'css/ie8fix.css';
            head.appendChild(link);
        }
    }
}
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
//~END~*/

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function feedback()
{
    var c_value = "";
    var cbValidate = 0;
    c_value = c_value + "FirstName: <u>Which is more economical?</u><br/>";
    for (var i=0; i < document.form1.question1.length; i++)
    {
        if (document.form1.question1[i].checked)
        {
            c_value = c_value + "<b>- " + document.form1.question1[i].value + "</b><br/>";
            cbValidate = cbValidate + 1;
        }
    }
    if(cbValidate==0){$get('wap-msg').innerHTML="Please fill up the form";return false;}
    cbValidate=0;
    
    c_value = c_value + "<br/>Question 2 : <u>To save cost on phonecalls, I would use</u><br/>";
    for (var i=0; i < document.form1.question2.length; i++)
    {
        if (document.form1.question2[i].checked)
        {
            c_value = c_value + "<b>- " + document.form1.question2[i].value + "</b><br/>";
            cbValidate = cbValidate + 1;
        }
    }
    if(cbValidate==0){$get('wap-msg').innerHTML="Please fill up the form";return false;}
    cbValidate=0;
    
    c_value = c_value + "<br/>Question 3 : <u>Trendiest way to shop for anything now?</u><br/>";
    for (var i=0; i < document.form1.question3.length; i++)
    {
        if (document.form1.question3[i].checked)
        {
            c_value = c_value + "<b>- " + document.form1.question3[i].value + "</b><br/>";
            cbValidate = cbValidate + 1;
        }
    }
    if(cbValidate==0){$get('wap-msg').innerHTML="Please fill up the form";return false;}
    cbValidate=0;
    $get('wap-msg').innerHTML="";
    
    var wname = $get('wap-name').value;
    var wemail = $get('wap-email').value;
    var wcontact = $get('wap-contact').value;
    var wsubject = "[Nexwave Telecom] - Win a Prize";
    var wheader = "<h3 style='color:rgb(11,51,140)'><u>NexWave - Win A Prize</u></h3><br/>";
    
    //alert(c_value);
    if(validateWAP() && echeck($get('wap-email').value,"wap-msg","wap-email"))
    {   
        if(isWinAPrize)
        {
            //wname =  wname.replace(/[^a-zA-Z 0-9]+/g,'');
            //wemail =  wemail.replace(/[^a-zA-Z 0-9]+/g,'');
            load('http://www.graphicfuse.com/webfuse.asmx/AJAXSendEmailNW?header='+wheader+'&subject='+wsubject+'&name='+wname+'&emailaddress='+wemail+'&contact='+wcontact+'&comment='+c_value,'wap-msg');
            isWinAPrize=false;
            $get('errMsg').innerHTML="";
        }
        else{$get('wap-msg').innerHTML="You have already submitted, please refresh page to try again";}         
    }
}

var isResellerRegister = true;
function resellerRegister(){$j(document).ready(function(){
    if(isResellerRegister){
        if(emailValidate($j("#rs-txtEmail").val(),"rs-txtEmail") && validateReseller()){
            var toemail = "product@nexwavetelecoms.com";
            var wemail = $j("#rs-txtEmail").val();
            var wsubject = "NexWave Telecoms - New Reseller Registration";
            var wheader = "<h3 style='color:rgb(11,51,140)'><u>NexWave Telecoms - Reseller Registration</u></h3><br/>";
            var whtml = "Name: <b>" + $j("#rs-txtName").val() + "</b><br/>";
            whtml += "Address: <b>" + $j("#rs-txtAddress").val() + "</b><br/>";
            whtml += "Country: <b>" + $j("#rs-txtCountry").val() + "</b><br/>";
            whtml += "Phone: <b>" + $j("#rs-txtPhone").val() + "</b><br/>";
            whtml += "Mobile: <b>" + $j("#rs-txtMobile").val() + "</b><br/>";
            whtml += "Fax: <b>" + $j("#rs-txtFax").val() + "</b><br/>";
            whtml += "Comment: <b>" +$j("#rs-txtComment").val() + " <br/>";
            
            if($j.browser.msie){
                document.getElementById("ajaxFrame").src = 'http://wanghe.sg/webfuse.asmx/AJAXSendMail?header='+wheader+'&subject='+wsubject+'&toemailaddress='+toemail+'&emailaddress='+wemail+'&html='+whtml;
                alert("Thank for your interest in becoming a reseller. We will contact you as soon as possible.");
                closePopup('popup-reseller');
            }
            else{
                ajaxLoad('http://wanghe.sg/webfuse.asmx/AJAXSendMail?header='+wheader+'&subject='+wsubject+'&toemailaddress='+toemail+'&emailaddress='+wemail+'&html='+whtml, 'reseller');
            }
            //$j.get('http://wanghe.sg/webfuse.asmx/AJAXSendMail?header='+wheader+'&subject='+wsubject+'&toemailaddress='+toemail+'&emailaddress='+wemail+'&html=');
            isResellerRegister=false;
        }
    }
    else{alert("Try again.");}
});
}

function validateReseller(){
    if($j("#rs-txtName").val()=="")
    {
        alert("Please enter your name.");
        return false;
    }
    if(isAlpha1($j("#rs-txtPhone").val())==false)
    {
        alert("Please enter numerical for phone.");
        return false;
    }
    if($j("#rs-txtMobile").val()=="")
    {
        alert("Please enter your mobile.");
        return false;
    }
    if(isAlpha1($j("#rs-txtMobile").val())==false)
    {
        alert("Please enter numerical for mobile.");
        return false;
    }
    return true;
}

var isWorkshopRegister = true;
function workshopRegister() {
    $j(document).ready(function () {
        if (isWorkshopRegister) {
            if (emailValidate($j("#ws-txtEmail").val(), "ws-txtEmail") && validateWorkshop()) {
                var wsTitle = $j(".pl-content h3.title").text();
                var toemail = "shivani.priyadarshini@nexwavetelecoms.com";
                var wemail = $j("#ws-txtEmail").val();
                var wsubject = "Workshop Registration : " + wsTitle;
                var wheader = "<h3 style='color:rgb(11,51,140)'><u>Nexwave Telecoms - Workshop Registration : " + wsTitle + "</u></h3><br/>";
                var whtml = "Name: <b>" + $j("#ws-txtName").val() + "</b><br/>";
                whtml += "Mobile: <b>" + $j("#ws-txtMobile").val() + "</b><br/>";
                whtml += "Company: <b>" + $j("#ws-txtCompany").val() + "</b><br/>";
                whtml += "Designation: <b>" + $j("#ws-txtDesignation").val() + "</b><br/>";

                var toemail2 = $j("#ws-txtEmail").val();
                var wsubject2 = "Workshop Registration";
                var wheader2 = "<h3 style='color:rgb(11,51,140)'><u>" + wsTitle + "</u></h3><br/>";
                var whtml2 = "Dear " + $j("#ws-txtName").val() + ",<br/><br/>";
                whtml2 += "Your have successfully registered for the event. You can call our hotline at <b>6486 8884</b> or email <a href=\"mailto:shivani.priyadarshini@nexwavetelecoms.com\">shivani.priyadarshini@nexwavetelecoms.com</a>";
                whtml2 += " if you have any enquires.<br/><br/>";
                whtml2 += "Thank you.";
                whtml2 += "<br/><br/>";
                whtml2 += "** This is a system-generated mail. Please do not reply to this mail. **<br/>";

                if ($j.browser.msie) {
                    document.getElementById("ajaxFrame").src = 'http://wanghe.sg/webfuse.asmx/AJAXSendMail?header=' + wheader + '&subject=' + wsubject + '&toemailaddress=' + toemail + '&emailaddress=' + wemail + '&html=' + whtml;
                    document.getElementById("ajaxFrame2").src = 'http://wanghe.sg/webfuse.asmx/AJAXSendMailNexwave?header=' + wheader2 + '&subject=' + wsubject2 + '&toemailaddress=' + toemail2 + '&emailaddress=' + wemail + '&html=' + whtml2;

                    alert("Thank for your registration.");
                    closePopup('popup-workshop');
                }
                else {
                    ajaxLoad('http://wanghe.sg/webfuse.asmx/AJAXSendMail?header=' + wheader + '&subject=' + wsubject + '&toemailaddress=' + toemail + '&emailaddress=' + wemail + '&html=' + whtml, 'workshop');
                    document.getElementById("ajaxFrame2").src = 'http://wanghe.sg/webfuse.asmx/AJAXSendMailNexwave?header=' + wheader2 + '&subject=' + wsubject2 + '&toemailaddress=' + toemail2 + '&emailaddress=' + wemail + '&html=' + whtml2;
                }
                //$j.get('http://wanghe.sg/webfuse.asmx/AJAXSendMail?header='+wheader+'&subject='+wsubject+'&toemailaddress='+toemail+'&emailaddress='+wemail+'&html=');
                isWorkshopRegister = false;
            }
        }
        else {
            if (!$j.browser.safari) {
                alert("You cannot submit twice please refresh to try again.");
            }
        }
    });
}
function validateWorkshop() {
    if ($j("#ws-txtName").val() == "") {
        alert("Please enter your name.");
        return false;
    }
    if ($j("#ws-txtMobile").val() == "") {
        alert("Please enter your mobile.");
        return false;
    }
    if (isAlpha1($j("#ws-txtMobile").val()) == false) {
        alert("Please enter numerical for mobile.");
        return false;
    }
    if ($j("#ws-txtCompany").val() == "") {
        alert("Please enter your company.");
        return false;
    }
    if ($j("#ws-txtDesignation").val() == "") {
        alert("Please enter your designation.");
        return false;
    }
    return true;
}


function isAlpha1(argvalue) {
  argvalue = argvalue.toString();
  var validChars = "/0123456789 +-)(";
    for (var n = 0; n < argvalue.length; n++) {
        if (validChars.indexOf(argvalue.substring(n, n+1)) == -1)
         return false;
    }
}


//AJAX LOAD HTML
function ajaxLoading(url, target) {
    //document.getElementById(target).innerHTML = "Loading...";
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (req != undefined) {
        req.onreadystatechange = function() {ajaxLoadDone(url, target);};
        req.open("GET", url, true);
        req.send("");
    }
}
var path = document.location.href
var dir = path.substring(0,path.indexOf('/nexwavetelecoms/', 1)+1);

function ajaxLoadDone(url, target) {
    if (req.readyState == 4) { // only if req is "loaded"
        if (req.status == 200) { // only if "OK"
        var formattedText = req.responseText;
        formattedText = formattedText.replace(/~/,dir+"nexwavetelecoms");

        //document.getElementById(target).innerHTML = formattedText;
        //document.getElementById(target).innerHTML = "";
        alert("Success, thank you for subscribing.");
    } 
    else {
        //document.getElementById(target).innerHTML="Communication Error:\n"+ req.status + "\n" +req.statusText;
        //document.getElementById(target).innerHTML = "";
	var msg = "Success, thank you for subscribing.";
        closePopup('popup-reseller');
        if (target == "reseller") { msg = "Thanks for your interest in becoming a reseller. We will contact you as soon as possible." }
        if (target == "workshop") { msg = "Thanks for your registration."; closePopup('popup-workshop'); alert(msg); return; }
        else if (target == "none") { return; }
        if(req.statusText=="OK") {alert(msg);}
        else if(req.status =="0") {alert(msg);}
        else{alert("Communication Error:\n"+ req.status + "\n" +req.statusText);}
    }
  }
}
function ajaxLoad(name, div) {
    ajaxLoading(name,div);
    return false;
}


function emailValidate(str,element) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if(str=="" || str=="Your email address"){
		//document.getElementById(element).value="Your Email Address";
		alert("Please enter your e-mail address");
		return false;
	}
	if (str.indexOf(at)==-1){
	   alert("Please enter your e-mail address");
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Please enter your e-mail address");
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Please enter your e-mail address");
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Please enter your e-mail address");
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please enter your e-mail address");
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Please enter your e-mail address");
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Please enter your e-mail address");
	    return false
	 }
	 return true				
}