/* CSS IE PATCH */
function iePatch(){
		if ( $.browser.msie ) {   
				$('#texts-scrollable').css('height','29px');
				$('#icon-chch-quake').css('width','30px ');
				$('#icon-fuel').css('width','30px ');
				$('#icon-severe-weather').css('width','30px ');
		}
	}




function Banner(){
	this.title=''
    this.image=''
	this.type=''
    this.link=''
    this.target=''
    this.htm=''
	
}
// set to true for using slides or to false for hiding the slides
var useSlides=true;
// set static slide to true for animating the sildes.
var animateSlides=true;

// base url for test//
var ROOT="http://updates.nzcextras.co.nz/";
var BASE_IMAGE_URL=ROOT+"/banners/images/"
// set to true for using the banner or to false for hiding the banner
//Banner Types
var HTML=1;
var FLASH=2;
var IMAGE=3;
var NONE=4;

// use only HTML,FLASH,IMAGE,NONE

var textSlides = new Array();
var imageSlides = new Array();




// text slides 
/*// use only HTML,FLASH,IMAGE
textSlides.push({ 
    title: 'Polar Blast Update',
    url: null,
    link: 'http://updates.nzcextras.co.nz/si_weather.html',
	type:HTML,
    target:'_self',
    html: '<span id="icon-severe-weather" class="text-icon">&nbsp;</span><span class="update-date">Friday 19th August 2011 </span>'+
    '<span class="update-description">- For the Latest Polar Blast Update, click here...</span>'
});*/
textSlides.push({ 
    title: 'Christchurch Earthquake Update',
    url: null,
	type:HTML,
    link: 'http://updates.nzcextras.co.nz/chc_earthquake.html',
    target:'_self',
    html: '<span id="icon-chch-quake"  class="text-icon">&nbsp;</span><span class="update-date">28th December 2011</span>'+
    '<span class="update-description"> - For the Latest Christchurch Earthquake Update, click here...</span>'
});
/*textSlides.push({ 
    title: 'Fuel Factor Update',
    url: null,
    link: 'http://www.nzcouriers.co.nz/html/domestic_fff.html',
	type:HTML,
    target:'_self',
    html: '<span id="icon-fuel"  class="text-icon">&nbsp;</span><span class="update-date">Wednesday 22nd June 2011</span>'+
    '<span class="update-description"> - For the current fuel factor % for domestic services, click here...</span>'
});
//image slides
// use only HTML,FLASH,IMAGE
imageSlides.push({ 
    title: 'Loud Shirt Day',
	alt: 'Friday 16 September, 2011 - Register Here - loudshirtday.org.nz',
    url:BASE_IMAGE_URL+'loud-shirt-day.gif',
  	type:IMAGE,
    link: 'http://www.loudshirtday.org.nz/register',
    target:'_blank',
	html:""
});
imageSlides.push({ 
    title: 'The crew at New Zealand Couriers salute the All Blacks – 2011 Rugby World Cup Champions... simply the best!',
	alt: 'The crew at New Zealand Couriers salute the All Blacks – 2011 Rugby World Cup Champions... simply the best!',
    url:BASE_IMAGE_URL+'ab_win.gif',
	type:IMAGE,
    link: null,
    target: null,
	html:""
});
imageSlides.push({ 
    title: 'On behalf of all New Zealand Couriers customers we have made significant Christmas donations to the Child Cancer Foundation and Keep New Zealand Beautiful.',
	alt: 'On behalf of all New Zealand Couriers customers we have made significant Christmas donations to the Child Cancer Foundation and Keep New Zealand Beautiful.',
    url:BASE_IMAGE_URL+'sponsorship.gif',
	type:IMAGE,
    link: null,
    target: null,
	html:""
});
imageSlides.push({ 
    title: 'New Zealand Couriers is proud to support Stars of Courage',
	alt: 'New Zealand Couriers is proud to support Stars of Courage',
    url:BASE_IMAGE_URL+'stars-of-courage-1.gif',
	type:IMAGE,
    link: 'http://www.childcancer.org.nz/How-you-can-help/Stars-of-Courage.aspx',
    target: '_blank',
	html:""
});
imageSlides.push({ 
    title: 'New Zealand Couriers is proud to support Stars of Courage',
	alt: 'New Zealand Couriers is proud to support Stars of Courage',
    url:BASE_IMAGE_URL+'stars-of-courage-2.gif',
	type:IMAGE,
    link: 'http://www.childcancer.org.nz/How-you-can-help/Stars-of-Courage.aspx',
    target: '_blank',
	html:""
});*/

	
/* DO NOT CHANGE CODE BELOW */
$(document).ready(
	function() {
	
		if(textSlides.length>1){
			textSlides.push(textSlides[0])
		}
		if(imageSlides.length>1){
			imageSlides.push(imageSlides[0])
		
		}
		// set the width an height for image usage for text slides
  		setSlides(textSlides,545,20,'jqb_slide','text-scroller-tr','texts');
		// set the width an height for image usage for image slide
	 	setSlides(imageSlides,545,60,'image_slide','image-scorller-tr','images')
		// banner content

		
		$('#texts').css('left','0px');	
		$('#images').css('left','2px');	
		
		
		var imageScrollable =$("#images-scrollable").data("scrollable"); 
 		var textScrollable 	=$("#texts-scrollable").data("scrollable"); 

	
		
		textScrollable.onSeek(function(event, index) { 
		 	if(index==textSlides.length-1){
				 this.begin(1);
				 
			}
		
		  }); 
		  
  		
		imageScrollable.onSeek(function(event, index) { 
		 	if(index==imageSlides.length-1){
				 this.begin(1);
				 
			}
		
		  }); 
 		
  		
			
			$('.jqb_slide').bind('mouseenter',
				function(){
					var id=$(this).attr('id')
					$('#'+id+' .update-date').css('color','#C10E0E');
					$('#'+id+' .update-description').css('color','#C10E0E');
				}
				
			)
			$('.jqb_slide').bind('mouseleave',
				function(){
					var id=$(this).attr('id')
					$('#'+id+' .update-date').css('color','#333333');
					$('#'+id+' .update-description').css('color','#333333');
				}
				
			)
			$('.jqb_slide').click(function(){
			
					var id=$(this).attr('id')
					
				//	$('#'+id+'-link').click(); 
				}
				
			)
				
			
	
		
		
	
	
			
		$(function() {
			//	$(".scrollable").scrollable({speed:1000, circular:true }).autoscroll({ autoplay: true, interval: 5000 });
		});
		iePatch()
	}
)


function setSlides(mySlides,w,h,myClass,tr,container){
    var html = ''
    for (var i = 0; i < mySlides.length; i++) {
        var slide = mySlides[i];
		
        html += '<div class="'+myClass+'" id="'+container+'-slide-' + i + '" title="' + slide.title + '" >';
if(container=="texts"){
		
		}
        if (slide.link != null) {
            html += '<a id="'+container+'-slide-'+i+'-link" href="' + slide.link + '" target="' + slide.target + '">'
        }
		
    	 html += getImageSlide(slide,w,h);
			  
        if (slide.link != null) {
            html += '</a>'
        }
		
        html += '</div>';
	
    }
	if(mySlides.length==1){
		$('#'+container+"-scrollable").removeClass('scrollable');	
	}
	if(mySlides.length==0){
		
		$('#'+tr).css('display','none');	
	}else{
		$('#'+container).html(html)
	}
	
	
}

function getImageSlide(banner,w,h){
	switch(banner.type){
		case HTML:
			return banner.html;
			break;
		case FLASH:
			return  getFlash(banner,w,h)
			break;
		case IMAGE:
			return  getImage(banner,w,h)
			break;
	}
}


function getFlash(slide,w,h){

	if( $.browser.msie ) {

		return  '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"  height="'+h+'" width="'+w+'" type="application/x-shockwave-flash"'+
				' id="flashBanner">'+
				' <param name="movie" value="'+slide.url+'"/>'+
				'<param name="wmode" value="transparent">'+
				'</object>'
	}
	
		return  '<object   height="'+h+'" width="'+w+'" type="application/x-shockwave-flash"'+
				' data="'+slide.url+'" id="flashBanner">'+
				'<param name="wmode" value="transparent">'+
				'</object>'
	
	
}
function getImage(slide,w,h){
	$("#bottom-banner").css('width',w+'px');
	$("#bottom-banner").css('height',h+'px');
	$("#bottom-banner").css('padding',0);
	$("#bottom-banner").css('background','')
	return '<image title="'+slide.title+'" alt="'+slide.alt+'" src="'+slide.url+'" width="'+w+'" height="'+h+'" border="0" />';	
	
}

 /*  
 
Images and links must have full url - http://...
 
 title- used for title and alt tags.
 image- can be <img ..> tag or null if there is no image   
 link- url 
 target- "_self","_blank"
 text- any html needed.
 
Data for text
  
 slides.push({ 
    title: 'Volcanic Ash Update',
    image: null,
    link: '/html/chc_earthquake.html',
    target:'_self',
    text: '<span class="update-date">Monday 27th June 2011 </span>'+
    '<span class="update-description">- For the Latest Christchurch Earthquake Update, click here...</span>'
 });
 
 
  data for image
 slides.push({ 
title: 'Volcanic Ash Update',
image: 'http://clients-maker.com/images/banner-slide-2.gif',
link: '/html/volcanic_ash_update.html',
target:'_self',
text: null

 
 sample output text only div  with link

 <div title="Volcanic Ash Update" id="slide-2" class="jqb_slide">
 <a target="_self" href="/html/volcanic_ash_update.html">
 <span class="update-date">Monday 27th June 2011 </span>
 <span class="update-description">- For the Latest Volcanic Ash Cloud Update, click here...</span>
 </a>
 </div>
       
 sample output text only div  without link

 <div title="Volcanic Ash Update" id="slide-2" class="jqb_slide">
 <span class="update-date">Monday 27th June 2011 </span>
 <span class="update-description">- For the Latest Volcanic Ash Cloud Update, click here...</span>
 </div>

 sample output image only div  with link

 <div title="Chrictchurch Earthquake" id="slide-3" class="jqb_slide">
 <a target="_self" href="/html/volcanic_ash_update.html">
 <img border="0" alt="Chrictchurch Earthquake" title="Chrictchurch Earthquake" src="http://clients-maker.com/images/banner-slide-1.gif">
 </a>
 </div>

 sample output image only div  without link

 <div title="Chrictchurch Earthquake" id="slide-3" class="jqb_slide">
 <img border="0" alt="Chrictchurch Earthquake" title="Chrictchurch Earthquake" src="http://clients-maker.com/images/banner-slide-1.gif">
 </div>





 */
