/*scroller*/
$(document).ready(function() {
	
	/*show video*/
	$('.scroller a').click(function(){
		$('#popup').css({'display':'block','height':'405px'});
		var src = video[$(this).find('img').attr('id').replace('id-','')];				
		$('#popup').html('<object width="500" height="405"><param name="movie" value="'+src+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+src+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="405"></embed></object>');
		overlay($('.main').width()); 
		$('#popup').css({'top': $(window).scrollTop() - 100 + "px"});
		return false;
	});	

	$('.scroller>ul').each(function(){
		$(this).width($(this).find('li').size()*87);
	});

	var motion = false;
	$('.clicker').click(function(){
		if(motion) return;
		if($(this).attr('id')=='next') var action = 'next';
		if($(this).attr('id')=='prev') var action = 'prev';				
		$('.scroller').each(function(){
			if($(this).css('display') == 'block'){
				var speed = 500;
				var id = $(this).attr('id');
				var w = $('#'+id+'>ul').width()*1;
				var l = $('#'+id+'>ul').css('left').replace('px','')*1;						
				if(w<=522) return;
				if(action=='next'){
					var offset = w-522+l;
					if(offset>522) {motion = true; $(this).find('ul').animate({'left': '-'+(522)+'px'},speed,function(){ motion = false });}
					if(offset<522) {motion = true; $(this).find('ul').animate({'left': '-'+(offset-l)+'px'},speed,function(){ motion = false });}
				}
				if(action=='prev'){
					var offset = l;
					if(offset<=-522) {motion = true; $(this).find('ul').animate({'left': (offset+522)+'px'},speed,function(){ motion = false });}
					if(offset>-522) {motion = true; $(this).find('ul').animate({'left': '0px'},speed,function(){ motion = false });}
				}
			}
		});
	});

	/*effect menu*/
	
	
	$('#accordion>li>a').click(function(){
		$('#accordion li').removeClass();
		$(this).parents('li').addClass('current');
	});			

	$("#accordion").accordion({ autoHeight: false, active: '#accordion>li.current>a'} );

	/*banners hover*/
	$('.banners img').mouseover(function(){
		$(this).css({'opacity':'0.8'});
	});
	$('.banners img').mouseout(function(){
		$('.banners img').css({'opacity':'1'});
	});		  

	/*effects tabs*/
	$('.tabs li').click(function(){
		$(this).parents('.tabs').find('li').removeClass('current');
		$(this).addClass('current');
		var id = '#id-'+$(this).attr('id');
		$(this).parents('.tabs').next('.block').find('.effect').each(function(i){
			$(this).css({'display':'none'});	
			$(id).css({'opacity':'0','display':'block'});
			$(id).animate({'opacity':'1'},300);
			$(id).css({'background-color':'white'});
		});
	});

	/*fixed height button*/			
	if ($.browser.msie && $.browser.version == 6) {
		$(window).scroll(function() {				
			$('#button').css({'top': $(this).scrollTop() + "px"});
		});
	}
	else {
		$('#button').css({'position':'fixed','top':'172px'});
	}

	/*show popup and overlay background*/
	$('body').click(function(){				
		$('#popup').css('display','none');
		$('#popup').empty();
		$('#feedback').remove();
		$('#overlay').remove();
	});
			
	$(window).resize(function(){
		if($('#overlay').attr('id')) overlay($('.main').width());			 
	});

	function overlay(width){
		$('#overlay').remove();
		if(width<1000) var width = '998px';
		else var width = '100%';
		$('body').append('<div class="overlay" id="overlay" style="position: absolute; z-index:5000; top:0; left:0; width: '+width+'; height: '+$('.main').height()+'px; background: black"></div>');
		$('#overlay').css({'opacity':'0.8'});
	}

	$('#button').click(function(){
		$('#popup').css({'display':'block','height':'auto'});
		$('#popup').html($('#formcontent').html());
		//$('#popup #formcontent').attr('id','feedback');
		$('#res-form').css('display','block');
		overlay($('.main').width()); 
		$('#popup').css({'top': $(window).scrollTop() - 100 + "px"});
		
		/*
		$('#popup').css({'display':'block','height':'auto'});
		$('#popup').html($('#template').html());
		$('#popup #template').attr('id','feedback');
		$('#feedback').css('display','block');
		overlay($('.main').width()); 
		$('#popup').css({'top': $(window).scrollTop() - 100 + "px"});
		*/
		return false;
	});

	$('#popup').click(function(){return false});
});

