$(document).ready(function(){
	var menu_width = 250;	
	var loader = '<div style="text-align: center; margin-top: 15px;"><img src="'+baseURL+'/wp-content/themes/ozpack/images/loader.gif" /></div>';
	$('#contentScroll').jScrollPane({showArrows: true});


	/* Menu animations */
	$("#menu_logo").css({"width": menu_width});
	$(".site_menu li").hover(function() {$(this).addClass("iehover"); 
	}, 
	function() { 
		$(this).removeClass("iehover"); 
	}); 
	
	$('.site_menu li a').hover(function() {
		$(this).animate({paddingLeft: '40px'}, {queue:false, duration: 150}); /*, easing:'easeOutQuart'*/
	},
	function(){
		$(this).animate({paddingLeft: '20px'}, {queue:false, duration: 150});
	});

	function show_menu() {
		var topval = 200;
		$("#menu_logo").css({"top": topval, "left": -$("#menu_logo").outerWidth()});
		$("#menu_logo").animate({"left": 0}, {"duration" : 1000, "easing" : "easeInOutCubic", queue: true});
	}
	/* other components*/
	
	$('.social_ico img').hover(function() {
		$(this).animate({right: '5px'}, {queue:false, duration: 150});
	},
	function(){
		$(this).animate({right: '0px'}, {queue:false, duration: 150});
	});					
	

	$("#shop_cart_btn").toggle(
		function () {
			$("#shop_cart_list").animate({"right" : 30});
		},
		function () {
			$("#shop_cart_list").animate({"right" : -240});
		}
	);	
	
	$("#my_profile_btn").toggle(
		function () {
			$("#my_profile_list").animate({"right" : 30});
		},
		function () {
			$("#my_profile_list").animate({"right" : -280});
		}
	);	
	
	show_menu();
	show_social_icons();
	show_shopcart();
	show_myprofile();
	
	jQuery('#signupbutton').live('click', function() {
		jQuery('.loginPadder, .signupPadder, .forgetPadder').hide();
		jQuery('.signupPadder').show();
	});		
	
	jQuery('#changebutton').live('click', function() {
		jQuery('.profilePadder').hide();
		jQuery('.changePadder').show();
	});		
	jQuery('#forgetbutton').live('click', function() {
		jQuery('.loginPadder, .signupPadder, .forgetPadder').hide();
		jQuery('.forgetPadder').show();
	});		
	jQuery('#signinbutton').live('click', function() {
		jQuery('.loginPadder, .signupPadder, .forgetPadder').hide();
		jQuery('.loginPadder').show();
	});	

	jQuery('#signup_submit').live('click', function() {
		var user_email = jQuery('#signup_email').val();
		var user_login = jQuery('#signup_username').val();	
		var oldContent = jQuery('.signupPadder').html();
		jQuery('.signupPadder').html(loader);
		jQuery.post(targetURL, { 
				gp_action: 'register',
				user_email: user_email,
				user_login: user_login
				},  function(data) {
					var obj = jQuery.parseJSON(data);
					if(obj.success == "false") {
						jQuery('.signupPadder').html(oldContent);
						jQuery('#registerError').html(obj.result);
					} else {
						jQuery('.signupPadder').html('<div id="registerResult">'+obj.result+'</div><a class="myloginlink cursory" id="signupbutton">Kayıt Ol</a> &nbsp; | &nbsp;<a class="myloginlink cursory" id="signinbutton">Giriş Yap</a>');
					}
				}
		); 		
	});	
	
	jQuery('#login_submit').live('click', function() {
		var username_signin = jQuery('#login_username').val();
		var password_signin = jQuery('#login_password').val();	
		var oldContent = jQuery('.loginPadder').html();
		jQuery('.loginPadder').html(loader);
		jQuery.post(targetURL, { 
				gp_login: 'login',
				username_signin: username_signin,
				password_signin: password_signin
				},  function(data) {
					var obj = jQuery.parseJSON(data);
					if(obj.success == "false") {
						jQuery('.loginPadder').html(oldContent);
						jQuery('#loginError').html(obj.result);
					} else {
						window.location.reload();
					}
				}
		); 
	});	

	jQuery('#forget_submit').live('click', function() {
		var user_email = jQuery('#user_forget_password').val();
		var oldContent = jQuery('#forgetPadder').html();		
		jQuery('.forgetPadder').html(loader);
		jQuery.post(targetURL, { 
			gp_forget_password: 'register',
			user_email: user_email
			},  function(data) {
					jQuery('.forgetPadder').html('<div id="passwordResult">'+data+'</div><a class="myloginlink cursory" id="signupbutton">Kayıt Ol</a> &nbsp; | &nbsp;<a class="myloginlink cursory" id="signinbutton">Giriş Yap</a>');
				
			});
	
		
	});	

	jQuery('#change_submit').live('click', function() {
		var old_password = jQuery('#change_password_old').val();
		var new_password = jQuery('#change_password_new').val();	
		var re_new_password = jQuery('#change_password_new_re').val();
		var oldContent = jQuery('#changePadder').html();		
		if(new_password != re_new_password) {
			jQuery('#passwordError').html('Yeni şifreler eşleşmiyor, lütfen tekrar deneyiniz.');
		} else {
			jQuery('.changePadder').html(loader);
			jQuery.post(targetURL, { 
				gp_change_password: 'register',
				old_password: old_password,
				new_password: new_password,
				re_new_password: re_new_password
				},  function(data) {
					var obj = jQuery.parseJSON(data);
					if(obj.success == "false") {
						jQuery('.changePadder').html(oldContent);
						jQuery('#passwordError').html(obj.result);
					} else {
						jQuery('.changePadder').html('<div id="passwordResult">'+obj.result+'</div>');
						setTimeout(function(){
							window.location = targetURL;
						},800);
					}
				}
			); 		
		}
	});		
});


function show_shop_cart(){
	if ($('#shop_cart_list').css('right') == '-240px') {
		$("#shop_cart_list").animate({"right" : 30});
	}
}

function show_shopcart() {
	$("#shop_cart_btn").css({"right": -100});
	$("#shop_cart_btn").animate({opacity: 1.0}, 1100).animate({"right": 0}, {"duration" : 1000, "easing" : "easeInOutCubic", queue: true});
}

function show_myprofile() {
	$("#my_profile_btn").css({"right": -100});
	$("#my_profile_btn").animate({opacity: 1.0}, 1100).animate({"right": 0}, {"duration" : 1000, "easing" : "easeInOutCubic", queue: true});
}

function show_social_icons() {
	$("#social_icons").css({"right": -150});
	$("#social_icons").animate({opacity: 1.0}, 1100).animate({"right": 0}, {"duration" : 1000, "easing" : "easeInOutCubic", queue: true});
}	

