$(document).ready(function(){

	$('a[rel=external]').click(function(){
		window.open(this.href);
		
		return false;
	});
	
	$('#lang li:first').css({
		paddingLeft:'5px',
		paddingRight:'5px',
		width:'17px',
		border:'0',
		background:'none'
	});
	
	$('#lang li').eq('1').css({
		paddingTop:'4px',
		borderTop:'1px solid #8b9599'
	});
	
	$('#lang li:last').css({
		paddingBottom:'4px',
		borderBottom:'1px solid #8b9599'
	});
	
	$('#lang li').next().hide();
	
	$('#lang li:first').toggle(function(){
		$(this).nextAll().show();
	}, function(){
		$(this).nextAll().hide();
	});
	

	
	$('#fontsize').toggle(function(){
		$('body').addClass('bigfont');
	}, function(){
		$('body').removeClass();
	});

	
	if($('.cw5').length){
		//CSBfleXcroll('scroll1');
		CSBfleXcroll('scroll2');
	
		$('.cw5 .w').hide();
		$('.cw5 .w2').show();
		
		$('.cw5 .nav a').click(function(){
			$(this).parent().each(function(){
				$('.cw5 .nav li[class=selected]').removeClass('selected');
				$(this).addClass('selected');						
			});
		
			var link = $(this).attr('href');
			
			$('.cw5 .w:visible').hide();
			$('.cw5 .w' + link).show();
			
			return false;
		});
		
		$('.cw5 .w .m a').click(function(){
			var link = $(this).attr('href');
			
			$('.cw5 .w:visible').hide();
			$('.cw5 .w' + link).show();
			
			return false;
		});	
	};	
	
	$('#mycarousel3').jcarousel({
		scroll: 3
	});	
	$('#mycarousel4').jcarousel({
		scroll: 4
	});	
	
	if($('.pw2').length){
		//$('.pw2 .w2 .c1').click(function(){
		//	window.open = $('a', this).attr('href');
		//	
		//	return false;
		//});
		
		$('.pw2 .w2 .c2').click(function(){
			document.location = $('a', this).attr('href');
		});
	};	
	
	$('.one input').click(function(){
		var c=$(this).attr('checked');
		$(this).parent().parent().parent().find('input[checked=true]').attr('checked', false);
		$(this).attr('checked', c);
	});	
	
	
	$('#continents-list span').hover(
		function(){
			$(this).css('color', '#96315D');
		},
		function(){
			$(this).css('color', '#8A92A5');
		}		
	);
	$('#countries-list span').hover(
		function(){
			$(this).css('color', '#96315D');
		},
		function(){
			$(this).css('color', '#8A92A5');
		}		
	);
	
	if($('#FilterFilter456').length)
		$('#FilterFilter456').next('label').css({'font-weight':'bold'});
	
	
});


Shadowbox.init({
	language: 'ru',
	players:  ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv']	
});		


function movie(){
	Shadowbox.open({
		content:    base+'files/film/player.html',
		player:     'iframe',
		width:      '640',
		height:     '400'				
	});
};	

function get_countries(id){
	select(1, 2);
	//$('#countries-box').show();
	$('#countries-box').spinner();
	url = base + 'distributors/get_countries/' + id;
	$.get(url, function(data){
		if (data.substr(0, 1) == 1) {
			$('#countries-box').html(data.substr(1));
			$('#continents-header span').html($('#hidden-continent').html());
		}
	})
	
}

function get_distributors(type, id){
	select(1, 2);
	$('#map-right-side').spinner();
	url = base + 'distributors/get_distributors/' + type + '/' + id;
	$.get(url, function(data){
		if (data.substr(0, 1) == 1) {
			$('#map-right-side').html(data.substr(1));
			$('#countries-header span').html($('#hidden-country').html());
			$('#continents-header span').html($('#hidden-continent2').html());
		}
	})
}

function tell_friend(msgOk, msgErr, type){
	email_to = encodeURIComponent($('#FriendEmailTo').val());
	email_from = encodeURIComponent($('#FriendEmailFrom').val());
	
	url = base + 'tell_friend/'+type;

	$.post(url, $('#FriendAddForm').serialize() , function(data){
		if (data.substr(0, 1) == 1) {
			$('#FriendFormMsg').html(msgOk);
			$('#FriendEmailTo').val('')
			$('#FriendEmailFrom').val('')
		}
		else
			$('#FriendFormMsg').html(msgErr);
	})
	
}



param = 1;
function select(nr, param_tmp){
	if (nr == 1) {
		el = $('#continents-list');
		el2 = $('#countries-list');
		el2.hide();
	}
	if (nr == 2){ 
		el = $('#countries-list');
		el2 = $('#continents-list');
		el2.hide();
	}
	if(param_tmp==1)
		param = 1;
	if(param_tmp==2)
		param = 2;
	//param = param_tmp;
	
	if (param == '1') {
		param = '2';
		el.animate({
			'opacity': '1'
		}, 300).show();
		//$('#arrow' + nr).attr('src', 'img/arrow_up.jpg');
	}
	else {
		param = '1';
		el.animate({
			'opacity': '0'
		}, 300).hide();
		//$('#arrow' + nr).attr('src', 'img/arrow_down.jpg');
	}
}


/*
$(document).ready(function(){

	$('#tell-me').click(function(){
	
			Shadowbox.open({
				content:    'articles/tell_friend',
				player:     'iframe',
				width:      '800',
				height:     '375'				
			});
			return false;
		}
	);
	

});*/
