jQuery.noConflict();

jQuery(function($) { 

	$("a[rel*='external']").attr( 'target', '_blank' );

	if($('.news-single-img a')[0]){
		$(".news-single-img a").removeAttr('onClick').fancybox({
				'type'	: 'ajax'
			});
	};

	$('#gallery-cycle').cycle({ 
	    fx:     'fade',
		speed:	'slow', 
	    timeout: 10000, 
	    next: '#next-slide',
		prev: '#prev-slide' 
	});
	
	if($('.download-form input')[0]){
		$('.download-form input').hint();
	};
	
	$('.project-detail dl dd:first, .project-detail dl dt:first').css({
		'background' : 'none',
		'padding-top' : '0'
	});	
	
	
	$('.big-image').after('<div class="thumbs"><a class="prev-image-gallery" href="#"></a><a href="#" class="next-image-gallery"></a><ul id="pag"></ul>').cycle({
    	fx:     'fade',
        speed:  'slow',
        pager:  '#pag',
		before: function(){
			//$('.next-image-gallery').click();
		},
        pagerAnchorBuilder: function(idx, slide) {
        var $img=$('img',slide);
            return '<li><a href="#"><img src="' + $img.attr('src')+ '" width="48" height="48" /></a></li>';
		}
    });
	
	var galNo = $('.big-image a').length
	if(galNo < 4){
		$('.prev-image-gallery, .next-image-gallery').css({"visibility":"hidden"});
	}

	function mycarousel_initCallback(carousel) {
	    jQuery('.next-image-gallery').click(function(event) {
			event.preventDefault();
	        carousel.next();
	    });
	
	    jQuery('.prev-image-gallery').click(function(event) {
			event.preventDefault();
	        carousel.prev();
	    });
	};
	
	
  	$('#pag').jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
	}); 
	
	//$('.big-image').galleryView();
	
	//$('.photoLightbox, .big-image a').fancybox();
	
	$('.photoLightbox, .big-image a').each(function(){
		var zoomHref = $(this).attr('href');
		$(this).append('<a href="'+zoomHref+'" class="zoom"></a>');
	});

	$('.footer-box .overlay').hover(
	  function () {
	    $(this).siblings('.subtitle').animate({height: '+=24' });
	  }, 
	  function () {
	    $(this).siblings('.subtitle').animate({height: '-=24' });
	  }
	);
	
	$('#footer-upper-inner > div > div:first .footer-box').css('margin-left','42px');
	$('#home #latest-news .latest-news-item:last').css('margin-bottom','5px');
	
	//Small validation on download form
	var form = $("#download-pdf");
	$("#download-pdf #submit").click(function() {
        form.validate({
				rules: {
					dlname: {
						required: true	
					}
				},
				messages: {
					dlname: {
						required: "asdasd"	
					}	
				}
		});
     });

	if ($.browser.msie && $.browser.version.substr(0,1)<8) {
		$('#nav li:last').css('width','165px');
	}
	
	$('.tx-irfaq-dynans-hidden').hide(0);
	
	$('[id^=opendiv]').each(function(){
		$(this).click(function(){
			var no = this.id.substr(7);
			if( $('.div'+no).is(":visible") )	$('.div'+no).hide(100);
			else								$('.div'+no).show(100);
		});
	});
	 
});
