$(document).ready(function() {
    // accordion-configuration
    $("#accordion").accordion({
        active: '.selected',
        fillSpace: false,
        header: '.accordion-header',
        animated: 'easeslide'
    });


    //BUGR-2647
    $("#adv-nav div.nav").hover(function() {
        $(this).css({"backgroundPosition":"left bottom",cursor:"default"});
        $("span", this).css({color:"#00476b",backgroundPosition:"right bottom"});
        $("a", this).css({color:"#00476b"});
    }, function() {
        $(this).css("backgroundPosition", "left top");
        $("span", this).css({color:"#fffffe",backgroundPosition:"right top"});
        $("a", this).css({color:"#fffffe"});
    });

    $('body').append('<div id="quiz-overlay"></div><div id="quiz-wrap"><iframe id="quiz-iframe" width="100%" height="100%" frameborder="0" border="0" cellspacing="0" scrolling="no" noresize="noresize" marginwidth="0" marginheight="0" src=""></iframe></div><div id="quiz-close"><img src="images/empty.gif" width="30" height="25"/></div>');
    $('#quiz-overlay').css({
        display:"none",
        backgroundColor:    "#02263C",
        opacity:            0.9,
        position:"absolute",
        top:0,
        left:0,
        zIndex:9000
    });
    $('#quiz-wrap').css({
        display:"none",
        width:"100%",
        position:"absolute",
        top:0,
        left:0,
        textAlign: "center",
        zIndex:10000,
        width:852,
        height:432
    });
    $('#quiz-close').css({
        display:"none",
        width:30,
        height:25,
        position:"absolute",
        top:0,
        left:0,
        zIndex:20000
    });
    var arrPageSizes = ___getPageSize();
    var arrPageScroll = ___getPageScroll();

    $("#adv-nav div.nav a").click(function() {
        $('#quiz-iframe').attr("src",$(this).attr("href").toString());        
        arrPageSizes = ___getPageSize();
        $('#quiz-overlay').css({
            width:                arrPageSizes[0],
            height:               arrPageSizes[1]
        }).fadeIn(function() {
            arrPageScroll = ___getPageScroll();
            $('#quiz-wrap').css({
            		width:852,
            		height:432,
                top:arrPageScroll[1] + (arrPageSizes[3] / 5),
                left:arrPageScroll[0] + (arrPageSizes[0] - 852) / 2
            }).fadeIn("fast",function(){
    					  $("#quiz-close img").attr("src","images/empty.gif");
      					$("#quiz-close img").css({opacity:1,width:30,height:25});
    						$("#quiz-close img").hover(function(){},function(){});            	                
                $('#quiz-close').css({
                		width:30,
                		height:25,                	
                    top:arrPageScroll[1] + (arrPageSizes[3] / 5),
                    left:arrPageScroll[0] + (arrPageSizes[0] - 852) / 2+852-30,
                    background: 'url(images/empty.gif) no-repeat left top'
                }).click(function(){
                    closeQuiz();
                }).hover(function(){
                    $(this).css({cursor:"pointer"});
                },function(){
                    
                }).show();
            });
        });

        return false;
    });

});
    //close
    function closeQuiz(){
        $('#quiz-close').hide();
        $('#quiz-overlay').fadeOut();
        $('#quiz-wrap').hide();
    }
		
    // If window was resized, calculate the new overlay dimensions
    $(window).resize(function() {
    		var wstr=$('#quiz-wrap').css('width');
    		var ww=Number(wstr.substring(0,wstr.length-2));
        // Get page sizes
        var arrPageSizes = ___getPageSize();
        // Style overlay and show it
        $('#quiz-overlay').css({
            width:    arrPageSizes[0]<900?900:arrPageSizes[0],
            height:   arrPageSizes[1]
        });
        // Get page scroll
        var arrPageScroll = ___getPageScroll();
        // Calculate top and left offset for the jquery-lightbox div object and show it
        $('#quiz-wrap').css({
            top:    arrPageScroll[1] + (arrPageSizes[3] / 5),
            left:    arrPageScroll[0] + (arrPageSizes[0] - ww) / 2
        });
        
        var closewstr=$('#quiz-close').css('width');
        var closeww=Number(closewstr.substring(0,closewstr.length-2));
        var borderW=12;
        if(closeww==30){
        	borderW=0;
        }
        
        $('#quiz-close').css({
            top:arrPageScroll[1] + (arrPageSizes[3] / 5)-borderW,
           left:arrPageScroll[0] + (arrPageSizes[0] - ww) / 2+ww-(closeww-borderW)
        })
    });
    function ___getPageSize() {
        var xScroll, yScroll;
        if (window.innerHeight && window.scrollMaxY) {
            xScroll = window.innerWidth + window.scrollMaxX;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
        var windowWidth, windowHeight;
        if (self.innerHeight) {    // all except Explorer
            if (document.documentElement.clientWidth) {
                windowWidth = document.documentElement.clientWidth;
            } else {
                windowWidth = self.innerWidth;
            }
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }
        // for small pages with total height less then height of the viewport
        if (yScroll < windowHeight) {
            pageHeight = windowHeight;
        } else {
            pageHeight = yScroll;
        }
        // for small pages with total width less then width of the viewport
        if (xScroll < windowWidth) {
            pageWidth = xScroll;
        } else {
            pageWidth = windowWidth;
        }
        arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
        return arrayPageSize;
    }

    function ___getPageScroll() {
        var xScroll, yScroll;
        if (self.pageYOffset) {
            yScroll = self.pageYOffset;
            xScroll = self.pageXOffset;
        } else if (document.documentElement && document.documentElement.scrollTop) {     // Explorer 6 Strict
            yScroll = document.documentElement.scrollTop;
            xScroll = document.documentElement.scrollLeft;
        } else if (document.body) {// all other Explorers
            yScroll = document.body.scrollTop;
            xScroll = document.body.scrollLeft;
        }
        arrayPageScroll = new Array(xScroll, yScroll);
        return arrayPageScroll;
    }

function goToConsultation(myStyle){
   	$('#quiz-wrap').fadeOut("fast",function(){
   		$('#quiz-iframe').attr("src","/consultation/start?style="+myStyle);
   		scroll(0,0);
	  	var arrPageSizes = ___getPageSize();
	  	var arrPageScroll = ___getPageScroll();	  	
    	$('#quiz-wrap').css({width:900,height:536,top:arrPageScroll[1] + (arrPageSizes[3] / 5),left:arrPageScroll[0] + (arrPageSizes[0] - 900) / 2}).fadeIn();
      $('#quiz-close').css({
        		width:51,
         		height:49,                	
            top:arrPageScroll[1] + (arrPageSizes[3] / 5)-12,
            left:arrPageScroll[0] + (arrPageSizes[0] - 900) / 2+900-39,
            background: 'url(/consultation/images/btn-close.png) no-repeat left top'            
      })    	
      $("#quiz-close img").attr("src","/consultation/images/btn-close-hover.png");
      $("#quiz-close img").css({opacity:0,width:51,height:49});
    $("#quiz-close img").hover(function(){
        // animate opacity to full
        $(this).stop().animate({
            opacity: 1
        }, 'fast');
    }, // on mouse out
 		function(){
        // animate opacity to nill
        $(this).stop().animate({
            opacity: 0
        }, 'fast');
    });      
   	});
}
function launchconsult(){
   		$('#quiz-iframe').attr("src","/consultation/start");
   		scroll(0,0);   		
	  	var arrPageSizes = ___getPageSize();
	  	var arrPageScroll = ___getPageScroll();	  	
	  	
        $('#quiz-overlay').css({
            width:                arrPageSizes[0],
            height:               arrPageSizes[1]
        }).fadeIn(function() {
    	$('#quiz-wrap').css({width:900,height:536,top:arrPageScroll[1] + (arrPageSizes[3] / 5),left:arrPageScroll[0] + (arrPageSizes[0] - 900) / 2}).fadeIn();
      $('#quiz-close').css({
        		width:51,
         		height:49,                	
            top:arrPageScroll[1] + (arrPageSizes[3] / 5)-13,
            left:arrPageScroll[0] + (arrPageSizes[0] - 900) / 2+900-39,
            background: 'url(/consultation/images/btn-close.png) no-repeat left top'            
      }).click(function(){
                    closeQuiz();
                }).show();    	
      $("#quiz-close img").attr("src","/consultation/images/btn-close-hover.png");
      $("#quiz-close img").css({opacity:0,width:51,height:49});
    $("#quiz-close img").hover(function(){
        // animate opacity to full
        $(this).stop().animate({
            opacity: 1
        }, 'fast');
    }, // on mouse out
 		function(){
        // animate opacity to nill
        $(this).stop().animate({
            opacity: 0
        }, 'fast');
    });      	        	
        });	  	
}