
//
// On load event
window.onload = function ()    {
    /*
    if ($('ddlink-1')) {
        Element.observe('ddlink-1', 'mouseover', function(event){
            light_box_show(1);
            
        });
    }
  
    if ($('ddlink-2')) {
        Element.observe('ddlink-2', 'mouseover', function(event){
            light_box_show(2);
            
        });
    }
  
	if ($('ddlink-3')) {
	    Element.observe('ddlink-3', 'mouseover', function(event){
	        light_box_show(3);
            
        });
    }
    
    
    if ($('ddlink-4')) {
        Element.observe('ddlink-4', 'mouseover', function(event){
	        light_box_show(4);
        });
    }

    
    if ($('ddlink-5')) {
	    Element.observe('ddlink-5', 'mouseover', function(event){
	        light_box_show(5);
        });
    }
    
    if ($('ddlink-6')) {
	    Element.observe('ddlink-6', 'mouseover', function(event){
	        light_box_show(6);
        });
    }
    
    if ($('ddlink-7')) {
	    Element.observe('ddlink-7', 'mouseover', function(event){
	        light_box_show(7);
        });
    }
    
    
*/ 
    
    
    // Check if there is any need to filter through all of these
    if ($('slide_down_1')) {
        if ($('slide_down_1')) {
            Element.observe('slide_down_1', 'click', function(event){
                toogle_show(1);
                
            });
        }
        
        if ($('slide_down_2')) {
            Element.observe('slide_down_2', 'click', function(event){
                toogle_show(2);
            });
        }
        
        if ($('slide_down_3')) {
            Element.observe('slide_down_3', 'click', function(event){
                toogle_show(3);
            });
        }
        
        if ($('slide_down_4')) {
            Element.observe('slide_down_4', 'click', function(event){
                toogle_show(4);
            });
        }
        
        if ($('slide_down_5')) {
            Element.observe('slide_down_5', 'click', function(event){
                toogle_show(5);
            });
        }
        
        if ($('slide_down_6')) {
            Element.observe('slide_down_6', 'click', function(event){
                toogle_show(6);
            });
        }
        
        if ($('slide_down_7')) {
            Element.observe('slide_down_7', 'click', function(event){
                toogle_show(7);
            });
        }
        
        if ($('slide_down_8')) {
            Element.observe('slide_down_8', 'click', function(event){
                toogle_show(8);
            });
        }
        
        if ($('slide_down_9')) {
            Element.observe('slide_down_9', 'click', function(event){
                toogle_show(9);
            });
        }
        
    }

}


//
// Lightbox methods
//


//
// Toggle lightbox on and off and create observer if its being shown
function light_box_show(position_number) {
    
    // Make sure all lightbox's are already closed
    any_closed = light_box_close_all();
    
    $("ddcontent-" + position_number).style.display = 'block';

    
    
    // Create event observer for close button
    window.setTimeout(function() {
        if ($("ddcontent-" + position_number).style.display != 'none') {
            Element.observe('close_lightbox_' + position_number, 'click', function(event){
                light_box_close(position_number);    
            });
           
           Element.observe("ddlink-" + position_number, 'mouseout', function(event){
    	        light_box_close(position_number);
            });
        }
    }, 100);
}


//
// Hide navigation lightbox
function light_box_close(position_number)    {
    //Effect.Fade("ddcontent-" + position_number, { duration: 0.2 });
    $("ddcontent-" + position_number).style.display = 'none';
}


//
// Close all lightbox's
function light_box_close_all()    {
    // Check if any others are active
    var loop_var = 1;
    var any_closed = false;
    
    while (loop_var < 10) {
        if ($("ddcontent-" + loop_var)) {
            if ($("ddcontent-" + loop_var).style.display == 'block')    {
                $("ddcontent-" + loop_var).style.display = 'none';
                any_closed = true;
            }
        }
        loop_var += 1;
    }
    
    return any_closed;
}


//
// drop down content
//


//
//
function toogle_show(content_area)    {
    
    // toggle show / hide 
    if ($("slide_down_content_" + content_area)) {
        Effect.toggle("slide_down_content_" + content_area, 'appear', {
            duration: 0.75
        });
    }
    
    // change background image
    if ($("slide_down_content_" + content_area).style.display == 'none') {
        
        // Vars
        var old_class_name = 'slide_down_title';
        var new_class_name = 'slide_down_title_active';
        
        var old_id_name = 'slide_down_' + content_area;
        var new_id_name = 'disabled_slide_down_' + content_area;

        
        if ($(old_id_name)){
            // Change id to a temp name
            $(old_id_name).setAttribute("id", new_id_name);
            
            // change id back
            window.setTimeout(function() {
                $(new_id_name).setAttribute("id", old_id_name); 
                
                $(old_id_name).className = new_class_name; 
                //$(old_id_name).setAttribute("class", new_class_name); // IE bug with setAttribute
            }, 780);
        }
        

    } else    {
        var new_class_name = 'slide_down_title';
        var old_class_name = 'slide_down_title_active';
        
        var old_id_name = 'slide_down_' + content_area;
        var new_id_name = 'disabled_slide_down_' + content_area;
                
        if ($(old_id_name)) {
            // change id back
            window.setTimeout(function(){
                $(old_id_name).className = new_class_name; 
                //$(old_id_name).setAttribute("class", new_class_name);// IE bug with setAttribute
            }, 780);
        }
    }
}


//
// Lightbox content
//


//
// Shows the lightbox
function lightbox_content_appear(instance_id)    {
    $('background_overlay').style.display = 'block';
    lightbox_content_open(instance_id);
}

//
// Close the lightbox
function lightbox_content_fade(instance_id)    {
    $('background_overlay').style.display = 'none';
    lightbox_content_close(instance_id)
}


//
//
function lightbox_content_open(instance_id)    {
    set_position("lightbox_content_" + instance_id);
    //$("lightbox_content_" + instance_id).style.display = 'block';
    Effect.Appear("lightbox_content_" + instance_id, { duration: 1 });  
}

//
//
function lightbox_content_close(instance_id)    {
    //$("lightbox_content_" + instance_id).style.display = 'none';
    Effect.Fade("lightbox_content_" + instance_id, { duration: 1 });  
}


//
// Set the position of the box
function set_position(id){   
    scroll_value = document.documentElement.scrollTop > document.body.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop; 
    $(id).style.top = (scroll_value + 100) + 'px';
    
    pa_offset = Position.cumulativeOffset($('left_corner_marker'));
    $(id).style.left = (pa_offset[0] + 70) + 'px';
}


//
// Check if IE 6
/*function is_ie_6(){
    var userAgent = navigator.userAgent.toLowerCase();
    version = (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1];
    msie = /msie/.test( userAgent ) && !/opera/.test( userAgent );
    
    if (version < 7 && msie){
        return true;
    } else {
        return false;
    }
}*/
