/**
 * @author jechrestler
 */
$(document).ready(function(){
	binding.add({
		'.flagBtn':{
				autoStart:false,
				selectedClass:'selectedFlag',
				afterSelect:function(el){
					$.get('setCountry.aspx?country=' + el.attr("href").replace("#", ""));
				}
			},
		'li img':{
			target:"li",
			selectedClass:'selected-image',
			beforeSelect:function(el){
				$('.selected-image img').animate({width:135, height:234, marginLeft:35, marginTop:45, opacity:.5});
			},
			afterSelect:function(el){
				//$('.selected-image img').animate({width:205, height:265, marginLeft:0, marginTop:0, opacity:1});
				var index = 0;
				$('.carousel-item').each(function(i){
					if($(this).hasClass('selected-image')){
						index = i;
					}
				})
				index -= 2;
				if(index > 0){
					carousel.next(index);
				}else{
					carousel.prev(index);
				}
				
				//carousel.setCurrentPage(page);
			},
			afterSelectAgain:function(el){
				window.location = el.children("a").attr("href");
			}
		}
	});
	$('a').bind('focus',function(){$(this).blur();})
	$(".carousel").carousel({scroll:1, cycle:true,
	onInit:function(carousel){
		window.carousel = carousel;
		$(".carousel img").css({display:"block"});
	},
	onPage:function(carousel, direction, el, index){
		var target = el;
		if(direction == "next" || direction == "none"){
			target = el.next().next();
		}if(direction == "prev" && index == 2){
			target = el.prev().prev();
		}
		target = target.find("img");
		$(".selected-image img").animate({width:135, height:234, marginLeft:35, marginTop:45, opacity:.5});
		target.animate({width:205, height:355, marginLeft:0, marginTop:0, opacity:1});
		$(".selected-image").removeClass("selected-image");
		target.parents("li").addClass("selected-image");
	}});
})

	