
(function ($) { 

var myMainDivsImgs=new Array("explore_icon","evaluate_icon","compare_icon","report_icon"); 
var myMainDivs=new Array("#explore_icon","#evaluate_icon","#compare_icon","#report_icon"); 
var mySubDivs=new Array("#explore_bubble","#evaluate_bubble","#compare_bubble","#report_bubble");

var myPanelsName=new Array("#explore_bubble","#evaluate_bubble","#compare_bubble","#report_bubble");
var myPanelsDirX=new Array("#explore_bubble","#evaluate_bubble","#compare_bubble","#report_bubble");

	
$(document).ready(function(){
					  
	// INIT EXTERNAL LINKS
	externalLinks();
	
	
	$('#division_line').delay(1000).fadeIn('slow');

	$('#explore_txt').delay(2000).fadeIn('slow');
	$('#evaluate_txt').delay(3000).fadeIn('slow');
	$('#compare_txt').delay(4000).fadeIn('slow');
	$('#report_txt').delay(5000).fadeIn('slow');
	
	$('#explore_icon').delay(2000).fadeIn('slow');
	$('#evaluate_icon').delay(3000).fadeIn('slow');
	$('#compare_icon').delay(4000).fadeIn('slow');	
	$('#report_icon').delay(5000).fadeIn('slow');	
	

  
	var i = 0;
	var timer = window.setInterval(		
	    function () {
/* 	        $('#explore_icon').animate({rotate: '-=10deg', left: '-=10px'}, 0, function() { */
		        i++;
		        if(i==1) {
		        	clearInterval(timer);
		        	
					//build in explore first
										
											//done with intro animation so bind 	
													for(var j = 0; j<myMainDivs.length; j++) {
														goHoverBind(myMainDivs[j], mySubDivs[j], myMainDivsImgs[j]);
													}		
											
											//$('#footer').unbind('mouseover.mySlideUp');
											//$('#footer').unbind('mouseleave.myDown');
											
											$('#silding_box').delay(2000).animate({top: '-=132',queue: false}, 1200, 'easeOutCirc', function () {
											
												$('#silding_box').delay(3000).animate({top: '+=132',queue: false}, 1200, 'easeOutCirc');				
						
						//$('#explore_bubble').delay(3000).fadeIn('slow');
					});	
					      	
		        	goBottomBoxBind();
		        	
		        }
			//});
/*
	        $('#evaluate_icon').animate({rotate: '-=10deg', left: '-=10px'}, 0);
	        $('#compare_icon').animate({rotate: '-=10deg', left: '-=10px'}, 0);
*/

	    },
	    30
	);	
				
	//goBottomBoxBind();
	
});


var footerState = false;
function goBottomBoxBind() 
{	
	$('#footer').bind('click.mySlideUp', function() 
	{
				
			if(!footerState)
			{
				$('#expanderLabel').text("[-] Contract");
				$('#silding_box').animate({top: '-=132',queue: false}, 1200, 'easeOutCirc');
			}
			else
			{
				$('#expanderLabel').text("[+] Expand");
				$('#silding_box').animate({top: '+=132',queue: false}, 1200, 'easeOutCirc')	
			}
			footerState = (footerState == true ) ? false : true;
			
	});
		
}

function goHoverBind(myDiv,mySubDiv, img) 
{	
	
	$(myDiv).bind('mouseover.myScaleUp', function() 
	{
		$(myDiv).css('background', 'url(sites/all/themes/corporateclean/images/'+img+'_over.png) 0 0 no-repeat');
				
		fadeOthers(mySubDiv);
	});	
	
	$(myDiv).bind('mouseleave.myScaleDown', function() 
	{
		
		$(myDiv).css('background', 'url(sites/all/themes/corporateclean/images/'+img+'.png) 0 0 no-repeat');	        	

	});
}

function loadPage(pname) 
{	
	
		   location.href = "explore-evaluate-compare#" + pname ;
	
}


function fadeOthers(mySubDiv) 
{	
	for(var k = 0; k<mySubDivs.length; k++) 
	{
		$(mySubDivs[k]).css('display', 'none');
	}
			
	$(mySubDiv).fadeIn('fast');	
	
}

// EXTERNAL LINKS - LOAD EXTERNAL LINKS IN A NEW WINDOW
function externalLinks() 
{
     if (!document.getElementsByTagName) return;
     var anchors = document.getElementsByTagName("a");
     for (var i=0; i<anchors.length; i++) 
	{
          var anchor = anchors[i];
     	if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
          anchor.target = "_blank";
     }
}

// CLEAR FORM TEXT FIELD WHEN CLICKED
function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
} 

function displayPanel(panel, dir_x, dir_y, id, size)
{	
alert('test');
	if ( size === undefined ) 
	{
     	size = '';
   	}

	// kinda have to hard code some things here. didn't get too fancy
	
	if(id != '1') { closePanel('explore', 'left', 'down', 1); }
	/*if(id != '2') { closePanel('explore', 'right', 'down', 2); }*/
	if(id != '3') { closePanel('explore', 'right', 'down', 3); }
	if(id != '4') { closePanel('explore', 'left', 'down', 4); }
	if(id != '5') { closePanel('explore', 'left', 'down', 5); }

	if(id != '1') { closePanel('evaluate', 'left', 'down', 1); }
	if(id != '2') { closePanel('evaluate', 'left', 'down', 2); }

	if(id != '1') { closePanel('compare', 'right', 'down', 1, '_med'); }
	if(id != '2') { closePanel('compare', 'left', 'down', 2, '_large'); }
	
	if( id != '1' ) { closePanel( 'report', 'left', 'down', 1, '_large' ); }
	if( id != '2' ) { closePanel( 'report', 'left', 'down', 2 ); }
	if( id != '3' ) { closePanel( 'report', 'right', 'down', 3 ); }
	if( id != '4' ) { closePanel( 'report', 'left', 'down', 4 ); }

	bringToFront( panel +'_interactive_tip_'+ id );	
	bringToFront( 'footer' );
	
	$( '#'+ panel +'_interactive_tip_label_'+ id+' a' ).removeClass( 'inactive_tip_'+ dir_x + size + '' );							
	$( '#'+ panel +'_interactive_tip_label_'+ id+' a' ).addClass( 'active_tip_'+ dir_x + size + '' );					
	$( '#'+ panel +'_interactive_tip_'+ id +'_expanded' ).fadeIn( 'slow' );	
	if( dir_y == "up" ) 
	{
			$( '#'+ panel +'_interactive_tip_'+ id +'_expanded').css('top', '-315px');
			$( '#'+ panel +'_interactive_tip_'+ id +'_expanded').css('padding-top', '15px');
			$( '#'+ panel +'_interactive_tip_'+ id +'_expanded').css('height', '270px');

			$( '.expanded_tip_right .content' ).css( 'height', '270px' );
			$( '.expanded_tip_left .content' ).css( 'height', '270px' );

			$( '#'+ panel +'_interactive_tip_'+ id +'_expanded .close_btn a' ).css( 'top', '-15px' );
			$( '#'+ panel +'_interactive_tip_'+ id +'_expanded .close_btn a' ).css( 'left', '265px' );

					
	}
} 

function closePanel(panel, dir_x, dir_y, id, size){	

	if ( size === undefined ) {
      size = '';
   }

	sendToBack(panel +'_interactive_tip_'+ id);
	bringToFront('footer');
	

	$('#'+ panel +'_interactive_tip_label_'+ id+' a').removeClass('active_tip_'+ dir_x + size + '');						
	$('#'+ panel +'_interactive_tip_label_'+ id+' a').addClass('inactive_tip_'+ dir_x + size + '');					
	$('#'+ panel +'_interactive_tip_'+ id +'_expanded').fadeOut('slow');	
	//$('#'+ panel +'_interactive_tip_'+ id +'_expanded').css('display','none');
}



/*
function callBoxFancyLoginError() {
	$("#loginerrorclick").fancybox().trigger('click');
}

function callBoxFancyLoggedOff() {
	$("#loggedoffclick").fancybox().trigger('click');
}

function callBoxFancySuccess() {
	$("#successclick").fancybox().trigger('click');
}


*/




/* some functions to bring divs to front */
function getAbsoluteDivs()
{
    var arr = new Array();
    var all_divs = document.getElementById("slider").getElementsByTagName("DIV");
    var j = 0;

    for (i = 0; i < all_divs.length; i++)
    {
        if (all_divs.item(i).currentStyle)
            style = all_divs.item(i).currentStyle.position;
        else
            style = window.getComputedStyle(
                all_divs.item(i), null).position;

        if ('absolute' == style)
        {
            arr[j] = all_divs.item(i);
            j++;
        }
    }
    return arr;
}

function bringToFront(id)
{
    if (!document.getElementById ||
        !document.getElementsByTagName)
        return;

    var obj = document.getElementById(id);
    var divs = getAbsoluteDivs();
    var max_index = 0;
    var cur_index;

    // Compute the maximal z-index of
    // other absolute-positioned divs
    for (i = 0; i < divs.length; i++)
    {
        var item = divs[i];
        if (item == obj ||
            item.style.zIndex == '')
            continue;

        cur_index = parseInt(item.style.zIndex);
        if (max_index < cur_index)
        {
            max_index = cur_index;
        }
    }

    obj.style.zIndex = max_index + 1;
}

function sendToBack(id)
{
    if (!document.getElementById ||
        !document.getElementsByTagName)
        return;

    var obj = document.getElementById(id);
    var divs = getAbsoluteDivs();
    var min_index = 999999;
    var cur_index;

    if (divs.length < 2)
        return;

    // Compute the minimal z-index of
    // other absolute-positioned divs
    for (i = 0; i < divs.length; i++)
    {
        var item = divs[i];
        if (item == obj)
            continue;

        if (item.style.zIndex == '')
        {
            min_index = 0;
            break;
        }

        cur_index = parseInt(item.style.zIndex);
        if (min_index > cur_index)
        {
            min_index = cur_index;
        }

    }

    if (min_index > parseInt(obj.style.zIndex))
    {
        return;
    }

    obj.style.zIndex = 1;

    if (min_index > 1)
        return;

    var add = min_index == 0 ? 2 : 1;

    for (i = 0; i < divs.length; i++)
    {
        var item = divs[i];
        if (item == obj)
            continue;

        item.style.zIndex += add;
    }
}


/* end some functions to bring divs to front */


})(jQuery);
