/*  
 *  Science Learning - jQuery Tabs and Ajax functions
 *  Copyright (c) 2008 Idris Corap (idris.corap@gmail.com) for CWA New Media (cwa.co.nz)
 *  
 */
 
 
$(function() {

// Init TABS
            $('#container-1 > ul').tabs();

/*                // Init Flash object: Banner
                $('#flash-banner').flash({
                src: 'swf/site-banner-linked.swf',
                width: '600',
                height: '112',
                quality: 'high',
	            majorversion: '9',
                build: '19',
                flashvars: { bgColor: 'blue', link:'/' }
                });*/

                // Init Flash object: Carousel
                $('#carousel-holder1').flash({
                src: 'swf/carousel3.swf' + '?' + Date(),
                width: 716,
                height: 400,
                quality: 'high',
	            majorversion: '9',
                build: '19' 
                });

                
                $('a.sci-ajax').click(function () {
                
                    // Get the HREF attribute from the A tag
                    var $this = $(this);
                    var params = $this.attr('href');

                    
    
                    $('#content-wide > .multimedia-loader > p.ui-tabs-loading > em').empty();   // Empty EM tag to remove the current message
                    var ajaxmsg = 'Loading&#8230;';
                    $('#content-wide > .multimedia-loader > p.ui-tabs-loading > em').prepend(ajaxmsg);
                    $('#content-wide > .multimedia-loader').show();
                    
                    
                    // Set up Ajax and pull HTML file from server
                    // Functions for ERROR and SUCCESS are also set up
                    $.ajax({
                        url:params,
                        dataType: 'html',
                        cache: false,
                        error: function(){
                        //alert('ERROR');
                        
                        $('#content-wide > .multimedia-loader > p.ui-tabs-loading > em').empty();
                        var ajaxmsg = 'Error&#8230;';
                        $('#content-wide > .multimedia-loader > p.ui-tabs-loading > em').prepend(ajaxmsg);
                        
                    
                        },
                        success: function(contexts){
                        //alert('OK');

                        $('#content-wide > .multimedia-loader').hide();               // Hide the loader
                        $('#content-wide > .multimedia').remove();                    // Remove the MULTIMEDIA class
                        $('#content-wide').append(contexts);                          // Inject the fetched Ajax content
                        
                        }                
                            
                    });
            
                return false;
            
                });
                
                
                // wSlide init - Only on context landing pages
                $("#wSlide1").wslide({
                  width: 443,
                  height: 174,
                  autolink: false,
                  fade: true,
                  duration: 1500
                });

                
                var sl = 0;
                var slides =  $('li', '#wSlide1').size();
                var rotation = setInterval(function() {

                    sl = ++sl <= slides ? sl : 0;
                    $('#wSlide1-nav > li:eq('+sl+') > a').trigger('click');
                   
                }, 7000);                    
                
      
                
                $('#wSlide1-nav > li > a').click(function(e) {
                        if (e.clientX && rotation) { // true mouse click ocurred stop auto rotate
                            
                            clearInterval(rotation);
                            rotation = null;                            
                        }
                });                

                
});

                
              

