// add curve corner support for all browsers
DD_roundies.addRule('.header_menu ul li a', '8px 0px 8px 0px');
DD_roundies.addRule('.search_box', '0px 0px 10px 10px');
DD_roundies.addRule('.search_textbox', '0px 0px 0px 5px');
DD_roundies.addRule('.post-date', '10px 0px 10px 0px');
DD_roundies.addRule('.read-more', '15px 15px 15px 15px');
DD_roundies.addRule('.widget_header', '0px 10px 0px 10px');
DD_roundies.addRule('.pagination a, .pagination span', '15px 15px 15px 15px');
DD_roundies.addRule('.post-share', '10px 0px 10px 0px');

$(document).ready(function(){
	
	// show/hide search box when mouse move on it
	$(".search_box").mouseover(function(){
		$(this).addClass("search_box_expand");
		$(".search_textbox").show();
	});

	$(".search_box").mouseout(function(){
		if($(".search_textbox").val()=="") {
			$(this).removeClass("search_box_expand");
			$(".search_textbox").hide();
		}
	});
	
	// rotate social media buttons when mouse move on it
	$(".rss_btn, .twitter_btn, .facebook_btn, .googleplus_btn, .linkedin_btn, .git_btn").rotate({ 
	   bind: 
		 { 
			mouseover : function() { 
				$(this).rotate({animateTo:360});
			},
			mouseout : function() { 
				$(this).rotate({animateTo:0});
			}
		 } 
	   
	});
	
	// preload images
	preload([
		'/wp-content/themes/aslam/images/twitter-bird.png',
		'/wp-content/themes/aslam/images/twitter-bird-2.png'
	]);
	
	// show/hide twitter box when mouse move on it
	$(".twitter_bird, .twitter_box").mouseover(function(){
		$(".twitter_bird").addClass('twitter_bird_flying');
		$(".twitter_box").css('margin-top', '-305px');
		$(".twitter_content").css('display', 'block');
		
		$(".twitter_box").addClass('tweet_box_borders');
	});
	
	$(".twitter_bird, .twitter_box").mouseout(function(){
		$(".twitter_bird").removeClass('twitter_bird_flying');
		$(".twitter_box").css('margin-top', '-5px');
		$(".twitter_content").css('display', 'none');
		
		$(".twitter_box").removeClass('tweet_box_borders');
	});
	
	// add glow effect on images when mouse move on it
	$( ".post a" ).mouseover( function() {
		$( this ).children( "img" ).stop( true, true ).animate({
			opacity: 0.6
		}, 400, "swing", function() {
			$( this ).animate({
				opacity: 1
			}, 400 );
		});
	});
	
	// apply prettyPhoto zoom effect on all images
	$("a[href$='.jpg'], a[href$='.jpeg'], a[href$='.gif'], a[href$='.png']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		show_title: false /* true/false */			
	});
	
	
	// comment form value hide on focus
	$("#author").focus(function(){
		if($(this).val() == 'Your Name *') { $(this).val(""); }
	});
	$("#author").blur(function(){
		if($(this).val() == '') { $(this).val("Your Name *"); }
	});
	
	$("#your_name").focus(function(){
		if($(this).val() == 'Your Name *') { $(this).val(""); }
	});
	$("#your_name").blur(function(){
		if($(this).val() == '') { $(this).val("Your Name *"); }
	});
	
	$("#email").focus(function(){
		if($(this).val() == 'Email *') { $(this).val(""); }
	});
	$("#email").blur(function(){
		if($(this).val() == '') { $(this).val("Email *"); }
	});
	
	$("#url").focus(function(){
		if($(this).val() == 'Website') { $(this).val(""); }
	});

	
	$("#respond #comment").focus(function(){
		if($(this).val() == 'Your Comment/Reply *') { $(this).val(""); }
	});
	
	$("#frmContact #comment").focus(function(){
		if($(this).val() == 'Your Message *') { $(this).val(""); }
	});
	
	$("#your_name, #email, #comment").blur(function(){
		check_contact_form();
	});
});

function check_contact_form(){
	error=0;
	
	if($("#your_name").val()=="" || $("#your_name").val()=="Your Name *"){
		error=1;
		$("#your_name").addClass("error");
	}
	else{
		$("#your_name").removeClass("error");
	}
	
	var email=$("#email").val();
	if(email=="" || $("#email").val()=="Email *"){
		error=1;
		$("#email").addClass("error");
	}
	else 
	if(email_check(email)==false){
		error=1;
		$("#email").addClass("error");
	}
	else{
		$("#email").removeClass("error");
	}
	
	if($("#comment").val()=="" || $("#comment").val()=="Your Message *"){
		error=1;
		$("#comment").addClass("error");
	}
	else{
		$("#comment").removeClass("error");
	}
	
	if(error==1){
		return false;
	}
	else{
		return true;
	}
}

//====== CHECK EMAIL ADDRESS VALID/INVALID ======//
function email_check(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true					
}

// Preload function for loading images
function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<img/>')[0].src = this;
        // Alternatively you could use:
        // (new Image()).src = this;
    });
}
