$(document).ready(function() {

	resizeImages();
	jQuery.event.add(window, "resize", resizeImages);

	var TIMER_VALUE = 10; // in seconds

	$('div.slideshow1 div.slides').cycle({
		slideExpr: ' .slide',
		cleartypeNoBg: ' true' ,
		fx: 'fade',
		timeout:30000, 
		startingSlide: Math.floor(Math.random()*5),
		pager: 'div.slideshow1 .controls',
		pagerAnchorBuilder: function(idx, slide) {
			var nothing = '';
			var ctrlLink = '<a href="#"><span>' + (idx + 1) + '</span></a>';
			var numSlides = $('div.slideshow1 .slide').size()
			var numControls = $('div.slideshow1 .controls a').size()
			return (numControls < numSlides) ? ctrlLink : nothing
		}
	});
	
	$('div.tabs div.tab-strip ul li a').click(function() {
  		$('div.tabs div.tab-strip ul li').removeClass('active');
		$(this).parent().addClass('active');
		$('div.box1 div.tab-content').removeClass('active');
		$("div#" + $(this).attr('href') + "-content").addClass('active');
		return false;
	});
	$('div.slideshow5 div.slides').cycle({
		activePagerClass: 'active',
		slideExpr: ' .slide',
		cleartypeNoBg: ' true',
		fx: 'fade',
		timeout: TIMER_VALUE * 1000,
		before: function(){
		    abortTimer();
		    $(this).parent().find('li.current').removeClass();
			$('.descriptionWrapper').stop().hide();
			$('.slideshow5 .slides .slide .image img').stop().css({opacity: '1'});
        },
		after: function(){
		    $(this).addClass('current');
		    resumeTimer();
        },
		pager: '.controls ul',
		pagerAnchorBuilder: function(idx, slide) { 
		// return selector string for existing anchor 
		return '.controls li:eq(' + idx + ')'; 
		}
	});
	$('div.slideshow5 div.slides').cycle('pause');

    $('.spiner').css({background: 'none'});
    resumeTimer();

	function resizeImages() {
	    var w = $(window).width();
	    var width = (w > 1291) ? w + "px" : "1291px";
	    $('.slideshow5 .slides .slide .image img').css("width", width);
	    $('.slideshow5 .slides .slide .image').css("width", width);
	}

    function resumeTimer() {
        $spiner = $('li.active .spiner');
		if ($spiner.length > 0) {
	    	$spiner.css({
	    	    background: 'none',
	    	    width: '40px',
	    	    height: '40px',
	    	    top: '4px',
	    	    left: '22px',
	    	    opacity: 1,
	    	    display: 'block',
	    	    visibility: 'visible'
	    	});
	        $spiner.polartimer({
	            opacity: 0.7,
	            color: '#EEE',
	            timerSeconds: TIMER_VALUE,
	            callback: function() {
					$('.descriptionWrapper').stop().hide();
					$('.slideshow5 .slides .slide .image img').stop().css({opacity: '1'});
					$('div.slideshow5 div.slides').cycle('next');
				}
	        }).polartimer('start');
		}
    }

    function abortTimer() { // to be called when you want to stop the timer
		$spiner = $('li.active .spiner');
		if ($spiner.length > 0) {
	        $('li.active .spiner').polartimer('destroy');
		}
    }

	$('.controls ul li .long .right .middle .info h2, .controls ul li .long .right .middle .info span a').click(function() {
		$('.descriptionWrapper').stop().hide();
		$('.slideshow5 .slides .slide .image img').stop().css({opacity: '1'});
		if ($('.slideshow5 .slides .slide').eq(jQuery(this).parents('li').index()).find('.description').html()){
			unh = false;
			$('.slideshow5 .slides .slide.current').css('display','none');
			$('.slideshow5 .slides .slide').eq(jQuery(this).parents('li').index()).css('opacity','1');
			$('.slideshow5 .slides .slide').eq(jQuery(this).parents('li').index()).show();
			$('.slideshow5 .slides .slide').eq(jQuery(this).parents('li').index()).find('.image img').animate({ opacity:'.3' },900);
			$('.slideshow5 .slides .slide .descriptionWrapper').stop().css({opacity: 0}).show();
			abortTimer();
			if ($.browser.msie() && $.browser.version.number() < 9) {
				$('.slideshow5 .slides .slide').eq(jQuery(this).parents('li').index()).find('.descriptionWrapper').stop().css({opacity: 1});				
				var fixFilter = 'alpha(opacity=100)';
				$('.descriptionWrapper').css({filter: ''});
				$('.descriptionWrapper h2, .descriptionWrapper img, .description h4, .description p').css({filter: fixFilter});
			}
			else {
				$('.slideshow5 .slides .slide').eq(jQuery(this).parents('li').index()).find('.descriptionWrapper').animate({opacity: 1}, 1000);
			}
		}
		else {
			resumeTimer();
		};
	});	


});

