
$(function()	{
	$('#lang_layer').hide();
	$('#lang_box').click(function()	{
		if($('#lang_layer').is(':hidden')) {
			$('#lang_layer').fadeIn(200);
			
		}else{
			$('#lang_layer').fadeOut(200);
		}
	});
	$('#lang_layer').hover( function() {},
  		function() { $('#lang_layer').fadeOut(200);
    });

	$('#search_query').click(function() {
		$('#search_query').val('');
	});
	$('#btn_basket').click(function(){
		location.href='shopping_cart.php';
	});

	$('.layer_cart').hide();
	$('.az_cart').click(function() {
		$('#loading').remove();
		$('.layer_news').hide();
		if($('.layer_cart').is(':hidden')) {
			$('.layer_cart').fadeIn(200);
			$('#cart_content').append('<div style="width:220px" id="loading"><br><br><br><center><img src="img/loading.gif"></center></div>');
			$.ajax({
				url: 'get_cart.php',
				contentType: 'text/html; charset=UTF-8',
				type: 'GET',
				data: 'repri_cart=9',
				success: function(data) {
					$('#loading').remove();
					$('#cust_cart_info').remove();
					$('#cart_content').append('<div id="cust_cart_info">'+ data +'</div>');
				}
			});
		} else {
			$('.layer_cart').fadeOut(200);
		}
	});
	$('.layer_cart').hover( function() {}, function() { $('.layer_cart').fadeOut(200); });
	
	
	$('.layer_news').hide();
	$('.az_news').click(function() {
		$('#loading').remove();
		$('.layer_cart').hide();
		if($('.layer_news').is(':hidden')) {
			$('.layer_news').fadeIn(200);
			// $('#news_content').append('<div style="width:220px" id="loading"><br><br><br><center><img src="img/loading.gif"></center></div>');
			// $.ajax({
			// 	url: 'newsletter_ajax.php',
			// 	type: 'POST',
			// 	data: 'email=' + $('#newsletter_email').val(),
			// 	success: function(data){
			// 		$('#loading').remove();
			// 		$('#cust_news_info').remove();
			// 		//$('#news_content').append('<div id="cust_news_info">'+ data +'</div>');
			// 		$('#news_content').append('<img src="img/r_okay.png">');
			// 	}
			// });
			
			$.ajax({
				url: 'get_cart.php',
				contentType: 'text/html; charset=UTF-8',
				type: 'GET',
				data: 'repri_cart=9',
				success: function(data) {
					
				}
			});
		} else {
			$('.layer_news').fadeOut(200);
		}
	});
	$('.layer_news').hover( function() {}, function() { $('.layer_news').fadeOut(200); });

});





$(function() {
	var options2 =
	            {
	                zoomWidth: 300,
	                zoomHeight: 300,
	                zoomType:'reverse',
					title: false,
					position : 'left',
					yOffset :0,
					xOffset :-20
	            };

	$(".jqzoom").jqzoom(options2);
});
function change_pic(tmp_node, highRes) {

	var highRes = (highRes == null) ? false : highRes;

	if(highRes == true)
		var neu_src = $('#'+tmp_node).attr("alt");
	else
		var neu_src = $('#'+tmp_node).attr("src"); 

	var neu_title = $('#'+tmp_node).attr("title");
	var neu_alt = $('#'+tmp_node).attr("alt");

	$('#mainpic').attr("href",neu_alt);
	$('#mainpic_small').attr("title",neu_title);
	$('#mainpic_small').attr("src",neu_src);

}






$(function()	{
	$('#cust_login').hide();
	$('#a_account').click(function()	{
		if($('#cust_login').is(':hidden')) {
			$('#cust_login').fadeIn(200);
			$('#newsletter_td inputa').click(function() {
				$('#cust_login_info').append('<div style="width:220px" id="loading"><br><br><br><center><img src="img/loading.gif"></center></div>');

				$.ajax({
					url: 'newsletter_ajax.php',
					type: 'POST',
					data: 'email=' + $('#newsletter_email').val(),
					success: function(data){
						$('#loading').remove();
						$('#sign_in').remove();
						$('#cust_login_info').append('<img src="img/r_okay.png">');
					}
				});
				return false;
			});
		}else{
			$('#cust_login').fadeOut(200);
		}
	});
	$('#cust_login').hover( function() {},
  		function() { $('#cust_login').fadeOut(200);
    });
});


// $(function()	{
// 	$('#cust_login').hide();
// 	$('#a_account').click(function()	{
// 		if($('#cust_login').css('display') == "block"){
// 			$('#cust_login').fadeOut(200);
// 		}else {
// 			$('#cust_login').fadeIn(200);
// 			$('#cust_cart').fadeOut(200);
// 			
// 			$('#lang_layer').fadeOut(200);
// 		}
// 	});
// 	$('#newsletter_td inputa').click(function() {
// 		$('#cust_login_info').append('<div style="width:220px" id="loading"><br><br><br><center><img src="img/loading.gif"></center></div>');
// 		
// 		$.ajax({
// 			url: 'newsletter_ajax.php',
// 			type: 'POST',
// 			data: 'email=' + $('#newsletter_email').val(),
// 			success: function(data){
// 				$('#loading').remove();
// 				$('#sign_in').remove();
// 				$('#cust_login_info').append('<img src="img/r_okay.png">');
// 			}
// 		});
// 		
// 		
// 		// $.ajax({
// 		// 	url: 'get_login.php',
// 		// 	type: 'POST',
// 		// 	data: 'action=process&email_address=' + $('#email_address').val() + '&password=' + $('#password').val(),
// 		// 	success: function(data){
// 		// 		$('#loading').fadeOut(200);
// 		// 		if(data == "loo01"){
// 		// 			$('#cust_login_info').remove();
// 		// 			$('#cust_login').append('<img src="img/login_right.png" height="140" width="170" />');
// 		// 			$('#cust_login').fadeOut(500);
// 		// 			$('#cust_login').remove();
// 		// 			$("#a_account").attr({ 
// 		// 			          href: "account.php"
// 		// 			});
// 		// 			location.reload(true);
// 		// 			
// 		// 		}else{
// 		// 			$('#lgginfo').remove();
// 		// 			$('#loading').remove();
// 		// 			$('#cust_login').effect("shake", { times:2 }, 100);
// 		// 			$('#cust_login_info').append('<p id="lgginfo">' + data + '</p>');
// 		// 		}
// 		// 	}
// 		// });
// 		
// 		return false;
// 	});
// });




function PressGrow(node,id) {
	if(node == "down"){ $('#'+id).removeClass('noActive'); } else { $('#'+id).addClass('noActive'); }
}



function openPopup(link){
	myWin = window.open(link, "Popup", "toolbar=0, scrollbars=yes, resizable=yes, height=400, width=600");
  myWin.focus();

}

function download_pdf(){
	var myPDF = $('#get_PDF').val();
	if(myPDF != '1x1'){
		window.open('dl_pdf.php?xfile='+myPDF);
		//console.log(myPDF);
	}
	
}

function getcountry(node) {
	if(node=="europe") { countr_id = 3; }
	if(node=="africa") { countr_id = 4; }
	if(node=="america") { countr_id = 1; }
	if(node=="asia") { countr_id = 5; }
	if(node=="australia") { countr_id = 6; }
	d_mouseover(true);
	$.ajax({
		url: 'mydealer.php',
		contentType: 'text/html; charset=utf-8',
		type: 'GET',
		data: 'mode=getCountries&cont_id='+countr_id,
		success: function (data) {
			$('.wm_content').remove();
			$('.wm_countries_content').remove();
			$('.wm_countries').append('<div class="wm_countries_content">'+data+'</div>').fadeIn(200);
			//$('.wm_countries').fadeIn(200);
		}
	});	
}

function getdealers(node) {
	set_active(node);
	$.ajax({
		url: 'mydealer.php',
		contentType: 'text/html; charset=utf-8',
		type: 'GET',
		data: 'mode=getDealers&land_id='+node,
		success: function (data) {
			$('.wm_content').remove();
			$('.wm_layer').append('<div class="wm_content">'+data+'</div>').fadeIn(200);
			//$('.wm_content').fadeIn(200);
		}
	});	
}

function set_active(node_a){
	$('.wm_countries_content').children('a').each( function() {
				if($(this).attr('id') == node_a)
					$(this).addClass('active');
				else
					$(this).removeClass('active');
			});
}

function d_mouseover(disable){
	if(disable){
	$.each($('.wm_area'),function()
			{
				this.onmouseover = '';
				this.onclick = '';
			});
	}
	else {
	$.each($('.wm_area'),function()
			{
				this.onmouseover = function(){wm_change(this.id)};
				this.onclick = function(){getcountry(this.id);return false;};
			});
	}

	
}

function wm_change(node) {
	$('.wm_layer').removeClass('america');
	$('.wm_layer').removeClass('asia');
	$('.wm_layer').removeClass('australia');
	$('.wm_layer').removeClass('africa');
	$('.wm_layer').removeClass('europe');
	$('.wm_layer').addClass(node);
}
function wm_remove() {
	$('.wm_countries_content').remove();
	$('.wm_countries').fadeOut(200);
	d_mouseover(false);
}

function load_ps() {
		$('#content_info').remove();
		$('#container_sl').remove();
		$('#product_box').remove();
		$('#content').append('<div class="grid_12" id="loading"><br><br><br><center><img src="img/loading.gif"></center></div>');
		
		$.ajax({
			url: 'get_gategories.php',
			contentType: 'text/html; charset=utf-8',
			type: 'GET',
			data: 'cat_id=0&cat_type1=img',
			success: function(data){
				$('#loading').fadeOut(200);
				$('#loading').remove();
				$('#content').append('<div id="content_info"></div>');
				$('#content_info').append(data);
			}
		});
		
		return false;
}

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


function open_products(){
		$('#content_info').remove();
		$('#container_sl').remove();
		$('#product_box').remove();
		$('#content').append('<div class="grid_12" id="loading"><br><br><br><center><img src="img/loading.gif"></center></div>');
		
		$.ajax({
			url: 'get_gategories.php',
			contentType: 'text/html; charset=utf-8',
			type: 'GET',
			data: 'cat_id=0&cat_type1=img',
			success: function(data){
				$('#loading').fadeOut(200);
				$('#loading').remove();
				$('#content').append('<div id="content_info"></div>');
				$('#content_info').append(data);
				$('#content_info').append('<br style="clear:both; />');
			}
		});
		
		return false;
}


function open_cat(id)	{
	
	
	if($('#loading')){
		$('#loading').remove();
	}
	$('#wech').remove();
	$('#content').append('<div class="grid_12" id="loading"><center><img src="img/loading.gif"></center></div>');
	$('#container_sl').remove();
	$('#product_box').remove();
	$('#content_info div').animate({"height": 66}, {duration: "slow" });
	$('#content_info').animate({"height": 66}, {duration: "slow" });
	var nav_trail = 0;
	if(id == 2 || id == 4) {
		open_sub_cat(id);
		nav_trail = 1;
		//open_sub_cat_new(id)
	} else {
		
			$.ajax({
				url: 'get_gategories.php',
				contentType: 'text/html; charset=UTF-8',
				type: 'GET',
				data: 'cat_id='+ id +'&cat_type1=slider',
				success: function(data){
					$('#loading').fadeOut(200);
					$('#loading').remove();
					$('#tmp_cInfo').remove();
					$('#content').append('<br id="wech" style="clear:both;line-height:2px;" /><div id="container_sl"><div class="sliderGallery sliderGallery_Cat_'+id+'"></div><br style="clear:both;" /></div>');
					$('.sliderGallery').append('<div class="left_'+id+'" /><ul class="imageLibrary">'+ data + '</ul><div class="slider ui-slider"><div class="handle"></div></div><div class="right_'+id+'" />');
					$('#container_sl').fadeIn(200);
					load_slide();
				}
			});
				
	}
	
	
	
	if(nav_trail == 1){
		return true;
	}else{
		return false;
	}
	
}




function open_sub_cat(cat_id, detailview ) {
	var detailview = (detailview == null) ? false : detailview;
	
	if(!detailview){
		var appe = '#content';
	}
	else
		var appe = '#detailNav';

	if($('#loading')){
		$('#loading').remove();
	}
	$.each($('.goAway'),function() {
				$(this).remove();
			});
	$(appe).append('<div style="width:800px" id="loading"><center><img src="img/loading.gif" /></center></div>');
	$.ajax({
		url: 'get_sub_categories.php',
		contentType: 'text/html; charset=UTF-8',
		type: 'GET',
		data: 'cat_id=' + cat_id,
		success: function(data)	{
			$('#loading').fadeOut(200);
			$(appe).append('<div id="product_box" class="goAway">'+data+'</div>');
			$('#loading').remove();
		}
	});
	return false;
}

function open_product_list(cat_id, main_id) {
	var main_id = (main_id == null) ? false : main_id;
	
	if(!main_id){
		var appe = '#content';
	}
	else
		var appe = '#detailNav';

	if($('#loading')){
		$('#loading').remove();
	}
	$.each($('#'+cat_id),function()
			{
				this.onclick = '';
			});

	setActiveSubCat(cat_id);
	$.each($('.placeholder'),function() {
				$(this).remove();
			});
	$(appe).append('<div style="width:800px" id="loading"><center><img src="img/loading.gif" /></center></div>');
	$.ajax({
		url: 'get_product_list2.php',
		contentType: 'text/html; charset=UTF-8',
		type: 'GET',
		data: 'cat_id=' + cat_id,
		success: function(data)	{
			$('#loading').fadeOut(200);
			$('#productsFromCat').append('<div id="placeholder" class="placeholder">'+data+'<br style="clear:both;" /></div>');
			$('#loading').remove();
			$.each($('#'+cat_id),function()
					{
						this.onclick = function(){open_product_list(this.id);};
					});
				}
	});
	return false;
}

function setActiveSubCat(activeSubCat){
	$.each($('.aCat'),function(){
				if($(this).attr('id') == activeSubCat)
					$(this).addClass('active');
				else
					$(this).removeClass('active');
	});
}


function pBoxItem_show(pID) {
	$('.pBoxItem').animate({ 'height' : '62px'}, 300, 'linear');
	$('.pBoxItem').removeClass('pBoxActive');
	$(pID).animate({ 'height' : '232'}, 400, 'linear');
	$(pID).addClass('pBoxActive');
}


function load_slide(){
    var container = $('div.sliderGallery');
    var ul = $('.imageLibrary');
    var itemsWidth = ul.outerWidth() - container.outerWidth();
    if(itemsWidth < 0){
	ul.css('left',(container.outerWidth() - ul.outerWidth())/2);
	productMaxWidth = 0;
	productMinWidth = 0;
	
	$('.slider', container).slider({ 
	  handle: '.handle',
	  minValue:productMinWidth, 
	  maxValue:productMaxWidth 
	});
	
	$('.slider').css('display', 'none');
	$('.slider', container).slider('destroy');
    }
    else{
	productMinWidth = 0;
	productMaxWidth = itemsWidth + 30;
	
	$('.slider', container).slider({ 
	  handle: '.handle',
	  minValue:productMinWidth, 
	  maxValue:productMaxWidth, 
	  stop: function (event, ui) {
	    ul.animate({ 'left' : ui.value * -1 },500,'linear');
	  }, 
	  slide: function (event, ui) {
	    ul.css('left',  ui.value * -1);
	  }
	});
    }

}

function navtrail(catID,subcatID) {
	$('#content_info').remove();
	$('#container_sl').remove();
	$('#product_box').remove();
	$('#content').append('<div class="grid_12" id="loading"><center><img src="img/loading.gif" /></center></div>');
	$.ajax({
		url: 'get_gategories.php',
		type: 'GET',
		data: 'cat_id=0&cat_type1=img',
		success: function(data){
			$('#loading').fadeOut(200);
			$('#loading').remove();
			$('#content').append('<div id="content_info"></div>');
			$('#content_info').append(data);
		}
	});
	if(open_cat(subcatID,'check') == false){
				open_sub_cat(subcatID);
			}
			
}



function oBlubb(blubbx){
 if(document.getElementById(blubbx).style.display=='block'){
  document.getElementById(blubbx).style.display='none';
 }else{
  document.getElementById(blubbx).style.display='block';
 }
}

function new_map2(map_name,maploc) {
  document.getElementById('mapx').src = maploc + 'img/' + map_name + '.png';	
}
function map_reset(maploc) {
  document.getElementById('mapx').src = maploc + 'img/europe_map.png';	
}

function go_country(map_locx,layer_name) {
  new_map2(layer_name,map_locx);
  
  for(i=1;i<25;i++){
  document.getElementById('layer_'+i).style.display = 'none';	
  }
  document.getElementById('layer_'+layer_name).style.display="block";	
}


function new_map(map_name) {
  document.getElementById('world_map').src = map_name + '.png';	
}

function go_map(map_name,layer_name) {
  new_map(map_name);
  document.getElementById('mleu').style.display = 'none';	
  document.getElementById('mlas').style.display = 'none';	
  document.getElementById('mlna').style.display = 'none';	
  document.getElementById('mlsa').style.display = 'none';	
  document.getElementById('mlau').style.display = 'none';	
  document.getElementById('mlaf').style.display = 'none';	
  document.getElementById(layer_name).style.display="block";	
}




function PressItem_show(pID) {
	$('.press_item').animate({ 'height' : '85px'}, 100, 'linear');
	$('.press_item').removeClass('pressItemActive');
	$(pID).animate({ 'height' : '232'}, 100, 'linear');
	$(pID).addClass('pressItemActive');
}
function PressItem_Close(pID) {
	$('.press_item').animate({ 'height' : '85px'}, 100, 'linear');
	$('.press_item').removeClass('pressItemActive');
}

function add_intro(lang){
	$('#content_info').append('<div class="goLeft"><img src="/images/intro_images/intro_bilder_'+lang+'.gif" alt="Artwizz Intro"/></div>');
}
