
(function($) {
    $(window).load(function () {

        $('.startpuff, .startpuff, .newspuff, .newspuff2, .case').click(function () {
            var url = $(this).find('a').attr('href');
            var target = $(this).find('a').attr('target')

            if (url != null) {
                if (target != null && target == "_blank")
                    window.open(url, "external");
                else {
                    window.location = url;
                }
            } else {
                return false;
            }

        });


		var centerImg = $('#slides img').width();
		var browserWidth = $(window).width();
		centerImg2  = browserWidth-centerImg;
		centerImg3  = centerImg2/2;
		$('#slides').width(centerImg);
		$('#slides').css("marginLeft", centerImg3);
		$('#slides').css("visibility", "visible");
		$(window).resize(function() {
			var centerImg = $('#slides img').width();
			var browserWidth = $(window).width();
			centerImg2  = browserWidth-centerImg;
			centerImg3  = centerImg2/2;
			$('#slides').width(centerImg);
			$('#slides').css("marginLeft", centerImg3);
			$('#slides').css("visibility", "visible");
		});

		var $container = $('#slides').cycle({
	       	fx: 'fade',
	       	speed: 500,
	       	timeout: 5000,
	       	cleartype: true,
	       	cleartypeNoBg: true,
	       	pager: '.nav',
	       	pagerAnchorBuilder: pagerFactory2
	    });
		var $container = $('#relslides').cycle({
	       	fx: 'fade',
	       	speed: 500,
	       	timeout: 5000,
	       	cleartype: true,
	       	cleartypeNoBg: true,
	       	pager: '.nav',
	       	pagerAnchorBuilder: pagerFactory2
	    });
		var $container = $('#caseslides').cycle({
	       	fx: 'scrollHorz',
	       	speed: 500,
	       	timeout: 5000,
	       	cleartype: true,
	       	cleartypeNoBg: true,
			continous: 1,
			prev:   '#prevcase', 
    		next:   '#nextcase'
	    });
	    function pagerFactory2(idx, slide) {
        	return '<li><a href="#">&nbsp;</a></li>';
	    };
		$('.startpuff').hover(function () {
			$(this).addClass('startpuffover');
		}, function () {
			$(this).removeClass('startpuffover');
		});
		$('.newspuff').hover(function () {
			$(this).addClass('startpuffover');
		}, function () {
			$(this).removeClass('startpuffover');
		});
		$('.newspuff2').hover(function () {
			$(this).addClass('startpuffover');
		}, function () {
			$(this).removeClass('startpuffover');
		});
		$('.case').hover(function () {
			$(this).addClass('caseover');
		}, function () {
			$(this).removeClass('caseover');
		});
	});	
	 $('div.startpuff').hover(function () {
		$(this).find('.photobg').fadeOut(100);
		$(this).find('.photobg2').fadeIn(100);
		$(this).find('.photoimg').stop().animate({ top: '-5px' }, 100, function() {    });
	}, function () {
		$(this).find('.photobg').fadeIn(100);
		$(this).find('.photobg2').fadeOut(100);
		$(this).find('.photoimg').stop().animate({ top: '0px' }, 100, function() {    });
	});
	 $('div.case').hover(function () {
		$(this).find('.photobg').fadeOut(100);
		$(this).find('.photobg2').fadeIn(100);
		$(this).find('.photoimg').stop().animate({ top: '-5px' }, 100, function() {    });
	}, function () {
		$(this).find('.photobg').fadeIn(100);
		$(this).find('.photobg2').fadeOut(100);
		$(this).find('.photoimg').stop().animate({ top: '0px' }, 100, function() {    });
	});
})(jQuery);
