/*******************************************************************************

	CSS on Sails Framework
	Title: GLJ
	Author: XHTMLized (http://www.xhtmlized.com/)
	Date: December 2010

*******************************************************************************/
var Site = {
	init : function(){
		Site.rotate();
		Site.slideshow();
		Site.carousel();
		Site.planPopup();
		Site.tab();
		
	},
	
	rotate : function(){
		$('#newsslider').hover(function(){
			$(this).stop();
			$(this).animate({right: 0}, 1000)
		}, function(){
			$(this).stop();
			$(this).animate({right: -380}, 1000)
		})
	},
	
	
	carousel : function(){
		if ($('ul.carousel, .gallery-carousel').length){
			$('ul.carousel, .gallery-carousel ul').jcarousel();
			
		}
		
		if ($('.gallery-carousel').length){
			//init
			var obj_items = $('.gallery-carousel > div > div.image > img');
			obj_items.not('.active')
					.removeClass('active')
					.css('opacity', 0.0)
					
			$('.gallery-carousel li.jcarousel-item').click(function(){
				obj_items.eq(i).stop();
				var i = $(this).index();
				obj_items.not(this).removeClass('active');
				obj_items.eq(i).addClass('active');
				obj_items.eq(i).animate({opacity: 1.0}, 1000, function(){
					obj_items.not(this).css('opacity', 0.0)
				});
				return false;
			})
		}
	},
	
	slideshow: function(){
		var obj = $('.slideshow');
		if (obj.length){
			obj.hover(function(){
				$(this).children('div.pagination').fadeIn();
			},function(){
				$(this).children('div.pagination').fadeOut();
			});
		}
	},
	
	planPopup : function(){
		$('.btn-site-plan').click(function(){
			$('body').x_overlay({trigger: true});
			$('.popup').fadeIn();
			return false;

		});
		
					//bind close button
			$('.popup .btn-close').click(function(){
				$(this).parent().fadeOut();
				$('body').x_overlay({trigger: false});
			})
		
	},
	
	tab: function(){
		if ($('.gallery').length){
			// init 
			var eq = $('.tab').children('a.current').index();
			/*
			$('.tab').parents('.section').children('.jScrollPaneContainer, .tab-content').hide();
			$('.tab').parents('.section').children('.jScrollPaneContainer, .tab-content').eq(eq).show();
			*/
			
			$('.section').children('.jScrollPaneContainer, .tab-content').hide();
			$('.section').children('.jScrollPaneContainer, .tab-content').eq(eq).show();
			
			$('.tab').children('a').each(function(i){
				$(this).click(function(){	
					
					if (!$(this).hasClass('btn-site-plan')){
						$(this).parents().siblings('.section').children('.jScrollPaneContainer, .tab-content').hide();
						$(this).parents().siblings('.section').children('.jScrollPaneContainer, .tab-content').eq(i).show();
						$(this).siblings().removeClass('current');
						$(this).addClass('current');
					}
					
					if ($(this).hasClass('postscrolltrigger')){
						$('.postscroll').jScrollPane({scrollbarWidth: 7, scrollbarMargin: 10});
					}
					
					return false;
					
					
				})
			})
		}
	}
	
	
	
}


$(document).ready(function() {

	Site.init();
	
	//trigger scrollPane for any div with the class scroll
	if ($('.scroll').length){
		$('.scroll').jScrollPane({scrollbarWidth: 7, scrollbarMargin: 10});
	}
	
	//trigger cycle for news slider
	if ($('#newsslider').length){
		$('.cycle').cycle({
			fx:     'scrollLeft',
			speed:  'fast',
			timeout: 5000,
			pager:  '.navi',
			next: '.next',
			prev: '.prev'
		});
	}
	
// DD_belatedPNG fix for IE6
if (typeof DD_belatedPNG !== 'undefined') {
	var PNG_fix_selectors = [
		'#navigation li.l',
		'.page-wrapper',
		'.page-wrapper span.b',
		'#home-sidebar .inner',
		'#home-sidebar .handler',
		'#home-sidebar',
		'#footer a.btn-inquire'
	];
	DD_belatedPNG.fix(PNG_fix_selectors.join(','));
}

});

