/**
 *
 * Dependencies: jQuery
 *
 */

jQuery.noConflict(); 
 
(function($) {
	$(function() {
		$("#scroller").simplyScroll();
	});
})(jQuery);

jQuery(document).ready(function($) {
		/*
		* Fix dropdown menu bootstrap error 
		* ------------------------------------------------- */
		$('.nav').find('li:has(ul)').addClass('dropdown');
		$('.dropdown > a').addClass('dropdown-toggle disabled');
		$('li.dropdown').children('ul.sub-menu').addClass('dropdown-menu');
		/*
		* Fix dropdown menu bootstrap error ends
		* --------------------------------------------------------- */	
    $('.dropdown .sub-menu').addClass('dropdown-menu');	
});

jQuery(document).ready(function($) {
    $('.dropdown > a').append('<b class="caret"></b>').dropdown();
    $('.dropdown .sub-menu').addClass('dropdown-menu');
});


jQuery(document).ready(function($) {
	$("#tabnav").idTabs(); 	
});

/* Swipe menu initial js */
jQuery(document).ready(function($) {
	jQuery('#responsive-menu-button').sidr({
		name: 'sidr-right',
		speed: 50,
		side: 'right',
		source: '#swipe-menu-responsive'	
	});
});

/* Image Preview Pretty Photo */
jQuery(document).ready(function($) {
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		social_tools : false,
		show_title : false,
		deeplinking: false,
	});
});

/* Twitter Widget */
jQuery(function($){
	$("#tickertweet").tweet({
		modpath: "/po-content/chingsy/js/twitter/",
		username: "DwiraSurvivor",
		page: 1,
		avatar_size: 48,
		count: 5,
		refresh_interval: 60,
		loading_text: "Loading Twitter Status...",
		template: '<div class="magz-twitter-tweet">' +
			'<a href="#">{avatar}</a>' +
			'<div class="twit-entry">{text}<div class="magz-twitter-tweet-time" id="magz-twitter-tweet-time-1">{time}</div></div>' +
			'<div class="clearfix"></div>' +
		'</div>'
	})
});

/* Subscribe Proses */
jQuery(document).ready(function($) {
	$("#magazine-subscribe-form").submit(function(){ // Checking subcribe form when submit to database
		var email = $("#magazine-subscribe-form input[type='text']").val();
		var email_pattern = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
		if (email_pattern.test(email) === false) {
			$("#magazine-subscribe-form input[type='text']").val('Masukan email yang benar...').css({'backgroundColor':'#ffb2b2'});
		} else {
			var submitData = $(this).serialize();
			$("#magazine-subscribe-form input[type='text']").attr('disabled','disabled');
			$("#magazine-subscribe-form input[type='submit']").attr('disabled','disabled');
			$.ajax({ // Subcribe process with AJAX
				type: "POST",
				url: "subscribe.php",
				data: submitData,
				dataType: "html",
				success: function(msg){
					if (parseInt(msg, 0) !== 0) {
						var msg_splits = msg.split("|");
						if (msg_splits[0] === 'success') {
							$("#magazine-subscribe-form input[type='submit']").removeAttr('disabled');
							$("#magazine-subscribe-form input[type='text']").removeAttr('disabled').val(msg_splits[1]).css({'backgroundColor':'#a5ffa5'}); 
						} else {
							$("#magazine-subscribe-form input[type='submit']").removeAttr('disabled');
							$("#magazine-subscribe-form input[type='text']").removeAttr('disabled').val(msg_splits[1]).css({'backgroundColor':'#ffb2b2'});
						}
					}
				}
			});
		}
		return false;
	});
});

/* Contact Proses */
jQuery(document).ready(function($) {
	$("#magazine-contact-form").submit(function() {
		var submitData = $('#magazine-contact-form').serialize();
		$("#magazine-contact-form input[name='name_contact']").attr('disabled','disabled');
		$("#magazine-contact-form input[name='email_contact']").attr('disabled','disabled');
		$("#magazine-contact-form input[name='subject_contact']").attr('disabled','disabled');
		$("#magazine-contact-form textarea[name='message_contact']").attr('disabled','disabled');
		$("#magazine-contact-form input[name='submit']").attr('disabled','disabled');
		$("#magazine-contact-form .data-status").show().html('<div class="note-box">Loading...</div>');
		$.ajax({ // Send an offer process with AJAX
			type: "POST",
			url: "contact.php",
			data: submitData,
			dataType: "html",
			success: function(msg){
				if (parseInt(msg, 0) !== 0) {
					var msg_splits = msg.split("|");
					if (msg_splits[0] === "success") {
						$("#magazine-contact-form input[name='name_contact']").val('').removeAttr('disabled');
						$("#magazine-contact-form input[name='email_contact']").val('').removeAttr('disabled');
						$("#magazine-contact-form input[name='subject_contact']").val('').removeAttr('disabled');
						$("#magazine-contact-form textarea[name='message_contact']").val('').removeAttr('disabled');
						$("#magazine-contact-form input[name='submit']").removeAttr('disabled');
						$("#magazine-contact-form .data-status").html('<div class="download-box">'+msg_splits[1]+'</div>').fadeOut(8000);
					} else {
						$("#magazine-contact-form input[name='name_contact']").removeAttr('disabled');
						$("#magazine-contact-form input[name='email_contact']").removeAttr('disabled');
						$("#magazine-contact-form input[name='subject_contact']").removeAttr('disabled');
						$("#magazine-contact-form textarea[name='message_contact']").removeAttr('disabled');
						$("#magazine-contact-form input[name='submit']").removeAttr('disabled');
						$("#magazine-contact-form .data-status").html('<div class="note-box">'+msg_splits[1]+'</div>').fadeOut(8000);
					}
					}
				}
		});
		return false;
	});
});

/* Contact Maps */
jQuery(document).ready(function($) {
	function initialize() {
	  var myLatlng = new google.maps.LatLng(-6.914744,107.609811);
	  var mapOptions = {
		zoom: 14,
		center: myLatlng
	  }
	  var map = new google.maps.Map(document.getElementById('googleMap'), mapOptions);

	  var marker = new google.maps.Marker({
		  position: myLatlng,
		  map: map,
		  title: 'Bandung Kota Kembang Gula'
	  });
	}

	google.maps.event.addDomListener(window, 'load', initialize);
});