$(document).ready(function() {
	
	$("#header_slideshow").css({'display': 'block'});
	
	var bc = $('#header_slideshow_button'); 	
	var bc2 = $('#header_slideshow_button2');
	
	if(ie==false)
	{
		var $slideshow = $('#header_slideshow').cycle({
				fx:      'scrollRight',
				delay:  -10000,
				timeout:  4000,
				speed: 2000,
				next: '#header_slideshow',
				easeIn: 'easeInOutBack',
				easeOut: 'easeInOutBack',
				/*before: function(){$('#header_slideshow_button2 #slide_btn_0').animate({opacity: 1}, 200, function() {})}*/
				before: function(curr,next,opts){
					resize();
					if((opts.currSlide+1)!=opts.slideCount)
					{
						$('#header_slideshow_button2 input').stop(true,true).animate({opacity: 0}, 1000, function() {});
						$('#header_slideshow_button2 #slide_btn_'+(opts.currSlide+1)).stop(true,true).animate({opacity: 1}, 1000, function() {})
					}
					else
					{
						$('#header_slideshow_button2 input').stop(true,true).animate({opacity: 0}, 1000, function() {});
					}
				},
				after: function(){
					/*resize();*/
			}
		});
	}
	else
	{
		var $slideshow = $('#header_slideshow').cycle({
			fx:      'scrollRight',
			delay:  -10000,
			timeout:  4000,
			speed: 1000,
			next: '#header_slideshow',
			/*before: function(){$('#header_slideshow_button2 #slide_btn_0').animate({opacity: 1}, 200, function() {})}*/
			before: function(curr,next,opts){
				resize();
				if((opts.currSlide+1)!=opts.slideCount)
				{
					$('#header_slideshow_button2 input').stop(true,true).animate({opacity: 0}, 1000, function() {});
					$('#header_slideshow_button2 #slide_btn_'+(opts.currSlide+1)).stop(true,true).animate({opacity: 1}, 1000, function() {})
				}
				else
				{
					$('#header_slideshow_button2 input').stop(true,true).animate({opacity: 0}, 1000, function() {});
				}
			},
			after: function(){
				/*resize();*/
			}
		});
	}
	
	$slideshow.children().each(function(i) { 
		// create input
		if(i<5){
			 $('<input type="button" value=" " />')
				// append it to button container 
				.appendTo(bc) 
				// bind click handler 
				/*.click(function() { 
						// cycle to the corresponding slide 
						$slideshow.cycle(i); 
						return false; 
				}); */
		}
	});
	
	$slideshow.children().each(function(i) { 
	// create input
	if(i<5){
	 $('<input type="button" value=" " id="slide_btn_'+(i+1)+'" />')
			// append it to button container 
			.appendTo(bc2) 
			// bind click handler 
			/*.click(function() { 
					// cycle to the corresponding slide 
					$slideshow.cycle(i);
					return false;
			}); */
	}
	});
	
});

$(window).resize(function () {
  resize();
});

function resize() {
  var thewidth = window.innerWidth;
  $(".slide").css("width", window.innerWidth);
  $(".slide").attr("width", window.innerWidth);
	$("#header_slideshow").css("width", window.innerWidth-30);
  $("#header_slideshow").attr("width", window.innerWidth-30);
}
