// JavaScript Document
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
	
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}


function show_message(html)
{
	$('body').append('<div id="dialog" align="center"></div>');
	$('#dialog').html(html);
	$('#dialog').dialog({title: "Message",
						resizable: false,
						modal: false
						});

}


hs.graphicsDir = "http://" + document.domain+"/scripts/highslide/highslide/graphics/";
hs.outlineType = 'rounded-white';
hs.wrapperClassName = 'draggable-header';
hs.align = 'center';



function explore_menu(id)
{
 $('#id_'+id + ' ul:first').each(function(){$(this).toggle('slow');});
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
	
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function show_login(submited, url)
{
	var data = '';
	if(!submited)
	{
	data = 'url='+url;
	
	$('.popup_form').remove();
	
	var w = $('body').width();
	var h = $('body').height();
	
	$('body').append("<div id='black_div'></div>");
	$('#black_div').css({'position':'absolute', 'top':'0px', 'left':'0px', 'width': w, 'height':h,'background-color':'#000','z-index':'100'});
	$('#black_div').fadeTo('slow',0.5);
	
	$('body').append("<div class='popup_form' id='login_form_container'></div>");
	}
	 else
	 {
	   data = 'login_form_submited=1&email='+$('#email').val()+'&pass='+$('#pass').val();
	   data = data+'&url='+url;
	 }
	$.ajax({
	  url: "/login_popup.php",
	  type:'POST',
	  data:data,
	  cache: false,
	  success: function(html)
	      {
		  $('#login_form_container').empty().html(html);
		  var wt = f_scrollTop()+($(window).height()-$('#login_form_container').height())/2;
		  var wl = ($(window).width()-$('#login_form_container').width())/2;
		  $('#login_form_container').css({'top':wt,'left':wl});
	  	  }
	  });

}

function show_register(submited)
{
	var data = '';
	if(!submited)
	{
	$('.popup_form').remove();
	
	var w = $('body').width();
	var h = $('body').height();
	
	$('body').append("<div id='black_div'></div>");
	$('#black_div').css({'position':'absolute', 'top':'0px', 'left':'0px', 'width': w, 'height':h,'background-color':'#000'});
	$('#black_div').fadeTo('slow',0.5);
	
	$('body').append("<div class='popup_form' id='register_form_container'></div>");
	}
	 else
	 {
	   data = 'register_form_submited=1&email='+$('#email').val()+'&password_1='+$('#password_1').val();
	   data+= '&password_2='+$('#password_2').val()+'&tel='+$('#tel').val()+'&name='+$('#name').val();
	   data+= '&city='+$('#city').val();
	 }
	$.ajax({
	  url: "/register_popup.php",
	  type:'POST',
	  data:data,
	  cache: false,
	  success: function(html)
	      {
		  $('#register_form_container').empty().html(html);
		  var wt = f_scrollTop()+($(window).height()-$('#register_form_container').height())/2;
		  var wl = ($(window).width()-$('#register_form_container').width())/2;
		  $('#register_form_container').css({'top':wt,'left':wl});
	  	  }
	  });

}

function close_form()
{
	$('#black_div').remove();
	$('.popup_form').remove();
}

function checkShippingmethod(ob)
{
	var ch = ob.checked;
	if(ob.value == 1 && ch) {$('#shipping_info').show('slow'); $('#select_office').hide('slow');}
	if(ob.value == 2 && ch) {$('#shipping_info').hide('slow'); $('#select_office').show('slow');}
}

function checkPayment(ob)
{	if(ob.checked && ob.value == 1){
	$('#shipping_method_1').attr('checked','checked'); $('#shipping_info').show('slow'); $('#select_office').hide('slow');$('#bank_pay_txt').hide('slow');
	}
	if(ob.checked && ob.value == 2){$('#shipping_method_2').attr('checked','checked'); $('#shipping_info').hide('slow'); $('#select_office').show('slow'); $('#bank_pay_txt').hide('slow');}
	
	if(ob.checked && ob.value == 3){$('#bank_pay_txt').show('slow');}
}

$(document).ready(function($){
	
	$("#main_menu_container").css({'z-index':'1'});					   
	$("#main_menu_container .menu_item").hover(
		function(){
			var w =$(this).width();
			$(this).children("ul").fadeIn(50);
			$(this).children("ul").css({'min-width':w});
			},
		function(){
			$(this).children("ul").fadeOut(50);
		}
	); //end hover
	
	$("#main_menu_container ul li").hover( 
		function(){
			var w =$(this).width();
			$(this).children("a").width(w-40);
			$(this).children("ul").css({'left': w, 'top':'0','position':'absolute'}).fadeIn(50);},
		function(){
			$(this).children("ul").fadeOut(50);
		}
	); //end hover
	
	
	
	$("#left_menu_container").css({'z-index':'2'});					   
	$("#left_menu_container .menu_item").hover(
		function(){
			var w =$(this).width();
			$(this).children("ul").css({'left': w, 'top':'0','position':'absolute'}).fadeIn(50);},
		function(){
			$(this).children("ul").fadeOut(50);
		}
	); //end hover
	
	$('#adv_photos').cycle({fx: "fade"});

})
//end document.ready
