// JavaScript Document
function change_value(me,papa){
	 value = $(me).attr('title');
        $("."+papa).val(value);
                                 
       			 
		var map2 = { 'stats': 'contain', 'stats2': 'contain2'
		}; 
        $.each(map2, function(key2, value2) {
            $('#'+value2).hide();
            $('#'+value2).css("opacity","0");
        });

}
function change_value21(me,papa,x){
        $("."+papa).val(me);
				price=0;
				count=0;
				
				if(me == 'FRANCE'){
				price=6;
				count=1;
				}
				if(me == 'EUROPE'){
				price=8;
				count=2;
				}
				if(me == 'NORTH AMERICA'){
				price=10;
				count=3;
				}
				if(me == 'ASIA'){
				price=10;
				count=4;
				}
				if(me == 'EUROPE'){
				price=8;
				count=5;
				}
				if(me == 'REST OF THE WORLD'){
				price=10;
				count=6;
				}
				if(me == 'FREE SHIPPING'){
				price=0;
				}
show_total_price(x,price,count);
}
$(document).ready(function(){ 
													 
	var map123 = {
		'stats': 'contain', 
		'stats2': 'contain2'
	}; 
	
	$.each(map123, function(key, value) { 
	var $layer = $('#'+value);	
	var $body  = $('html');
  $layer.bind( 'summon', function( e )
    {
			$('#'+value).hide();
			$layer.show().animate({
				opacity: 0.5
			}, "fast");
      $body.bind( 'click', dismissLayer );
    } ).bind( 'dismiss', function( e )
    {
			$layer.animate({
				opacity: 0
			}, "fast",function(){$layer.hide()});
      $body.unbind( 'click', dismissLayer );
    } ).click( function( e )
    {
      e.stopPropagation();
    }).trigger( 'dismiss' );

  function dismissLayer( e )
  {
    $layer.trigger( 'dismiss' );
		$layer.animate({
			opacity: 0
		}, "fast");
  }
  // This is optional - this just triggers the div to 'visible'
  $('.'+key).click( function( e )
  {
	var $layer = $('#'+value+':hidden');
		
		$.each(map123, function(key, value) {
			$('#'+value).hide();
			$('#'+value).css("opacity","0");
		});
			
    if ( $layer.length )
    {
      $layer.trigger( 'summon' );
      e.stopPropagation();
    }
  });
	});
});



/*

$(document).ready(function(){ 
	var map = {
		'stats': 'contain', 
		'stats2': 'contain2'
	}; 
	$.each(map, function(key, value) { 
	var $layer = $('#'+value);	
	var $body  = $('html');
	
  $layer
    .bind( 'summon', function( e )
    {
			$('#'+value).hide();
			//alert($layer.attr('id'));
			$layer.show().animate({
				opacity: 1
			}, "fast");
      $body.bind( 'click', dismissLayer );
    } )
    .bind( 'dismiss', function( e )
    {
			$layer.animate({
				opacity: 0
			}, "fast",function(){$layer.hide()});
      $body.unbind( 'click', dismissLayer );
    } )
    .click( function( e )
    {
      e.stopPropagation();
    })
    .trigger( 'dismiss' );

  function dismissLayer( e )
  {
    $layer.trigger( 'dismiss' );
		$layer.animate({
			opacity: 0
		}, "fast");
  }
  // This is optional - this just triggers the div to 'visible'
  $('.'+key).click( function( e )
  {
	var $layer = $('#'+value+':hidden');
		$.each(map, function(key, value) {
			$('#'+value).hide();
			$('#'+value).css("opacity","0");
		});
			
    if ( $layer.length )
    {
      $layer.trigger( 'summon' );
      e.stopPropagation();
    }
  });
	});
});*/

var page;
var cpage = 0;

$(document).ready(function(){
	page = $('.pSliderItem');
	$('#scroll_holder').width($('.pSliderItem').width()*page.length);	
	$('#page_slider').animate({
		scrollLeft:0
	});
	$('.prevPage_slide').css({opacity:0});
	$('.nextPage_slide').css({opacity:0});
	
	$('.prevPage_slide').mouseover(function(){
											$(this).animate({
													opacity: 1
											},'fast')
										})
	
	
	$('.prevPage_slide').mouseout(function(){
											$(this).animate({
												opacity: 0
											})
										})
	
	
	
	$('.nextPage_slide').mouseover(function(){
											$(this).animate({
													opacity: 1
											},'fast')
										})
	
	
	$('.nextPage_slide').mouseout(function(){
											$(this).animate({
												opacity: 0
											})
										})
	write_nav();
});

function next_page(){
	//alert($('#page_slider').scrollLeft() +" ------ "+ (($('.pSliderItem').width()*page.length)-980));
	if(cpage == page.length-1){
		cpage = 0;
	}else{
		cpage = cpage+1;
	}
	if($('#page_slider').scrollLeft() >= (($('.pSliderItem').width()*page.length)-980)){
		$('#page_slider').css({opacity:1}).animate({
												scrollLeft:0
											},'slow',function(){
				$(this).animate({
					opacity:1
				});
			})
	}else{
		$('#page_slider').css({opacity:1}).animate({
												scrollLeft:"+="+980
											},'slow',function(){
				$(this).animate({
					opacity:1
				});
			})
	}
	write_nav();
}


function prev_page(){
	if(cpage == 0){
		cpage = page.length-1;
	}else{
		cpage = cpage-1;
	}
	//alert($('#page_slider').scrollLeft() +" ------ "+ (($('.pSliderItem').width()*page.length)-980));
	if($('#page_slider').scrollLeft() == 0){
			$('#page_slider').css({opacity:0.5}).animate({
				scrollLeft:(($('.pSliderItem').width()*page.length)-980)
			},'slow',function(){
				$(this).animate({
					opacity:1
				});
			})

	}else{
		$('#page_slider')
			.css({opacity:0.5})
			.animate({
				scrollLeft:"-="+980
			},'slow',function(){
				$(this).animate({
					opacity:1
				});
			})
	}
	write_nav();
}

function write_nav(){
	//------ Left ------//
	if(cpage > 0 ){
		prev_text = $(page[cpage-1]).children('.title');
		$('.prevPage_slide').html(prev_text.val());
	}else{
		prev_text = $(page[page.length-1]).children('.title');
		$('.prevPage_slide').html(prev_text.val());
	}
	//------ Right ------//
	if(cpage == page.length-1){
		next_text = $(page[0]).children('.title');
		$('.nextPage_slide').html(next_text.val());
	}else{
		next_text = $(page[cpage+1]).children('.title');
		$('.nextPage_slide').html(next_text.val());
	}
}


function writeDiv(id,text){
	$('#'+id).html(text);
}

// some click event for iphone application
// by tom 
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
	$("a.dropper_1").bind('touchstart', function(){
 			console.log("touch started");
});
}
