/* User Scripts */

$(document).ready(function(){

/* Images hover */	

$("div.roundbox_photo a, div.roundbox_video a").append("<span></span>");
$("div.roundbox_photo a, div.roundbox_video a").hover(function(){
$(this).children("span").fadeIn(600);
  },function(){
    $(this).children("span").fadeOut(200);
  });
			


		$(".portfolio_full img, .portfolio_two img, .content_picture_prettyphoto img, .image-nav").hover(
		function() {
		$(this).animate({"opacity": "0.6"}, "slow");
		},
		function() {
		$(this).animate({"opacity": "1"}, "slow");
		});	
		
/* Social icons hover */
		
		$('#footer-widget-fourth .social-links img').fadeTo("fast","0.5");
		$("#footer-widget-fourth .social-links img").hover(
		function() {
		$(this).animate({"opacity": "1"}, "fast");
		},
		function() {
		$(this).animate({"opacity": "0.5"}, "fast");
		}); 		
		
		
/* TipTip Tooltips settings */
	  
    $(function(){
	$(".tt_bottom").tipTip({edgeOffset: 5, defaultPosition: "bottom"});
	});
	
    $(function(){
	$(".tt_top").tipTip({edgeOffset: 5, defaultPosition: "top"});
	});
	
	$(function(){
	$(".tt_left").tipTip({edgeOffset: 5, defaultPosition: "left"});
	});
	
	$(function(){
	$(".tt_right").tipTip({edgeOffset: 5, defaultPosition: "right"});
	});	
	
/* Scroll to Top */
	
	$('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });	

/* Pretty Photo Lighbox */
	
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animation_speed: 'fast', /* fast/slow/normal */
			slideshow: false, /* false OR interval time in ms */
			autoplay_slideshow: false, /* true/false */
			opacity: 0.80, /* Value between 0 and 1 */
			show_title: true, /* true/false */
			allow_resize: true, /* Resize the photos bigger than viewport. true/false */
			default_width: 500,
			default_height: 344,
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
			hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
			wmode: 'opaque', /* Set the flash wmode attribute */
			autoplay: true, /* Automatically start videos: True/False */
			modal: false, /* If set to true, only the close button will close the window */
			overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
			keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */
			changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
			callback: function(){}, /* Called when prettyPhoto is closed */
			markup: '<div class="pp_pic_holder"> \
						<div class="ppt">&nbsp;</div> \
						<div class="pp_top"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
						<div class="pp_content_container"> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_loaderIcon"></div> \
									<div class="pp_fade"> \
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
										<div class="pp_hoverContainer"> \
											<a class="pp_next" href="#">next</a> \
											<a class="pp_previous" href="#">previous</a> \
										</div> \
										<div id="pp_full_res"></div> \
										<div class="pp_details clearfix"> \
											<p class="pp_description"></p> \
											<a class="pp_close" href="#">Close</a> \
											<div class="pp_nav"> \
												<a href="#" class="pp_arrow_previous">Previous</a> \
												<p class="currentTextHolder">0/0</p> \
												<a href="#" class="pp_arrow_next">Next</a> \
											</div> \
										</div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
						<div class="pp_bottom"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
					</div> \
					<div class="pp_overlay"></div>',
			gallery_markup: '<div class="pp_gallery"> \
								<a href="#" class="pp_arrow_previous">Previous</a> \
								<ul> \
									{gallery} \
								</ul> \
								<a href="#" class="pp_arrow_next">Next</a> \
							</div>',
			image_markup: '<img id="fullResImage" src="" />',
			flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
			quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
			iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
			inline_markup: '<div class="pp_inline clearfix">{content}</div>',
			custom_markup: ''
			
	});
});


/* Contact Form */

function checkemail(emailaddress){
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); 
	return pattern.test(emailaddress); 
}

$(document).ready(function(){ 
	var $math1 = Math.floor( Math.random() * (100) );
	var $math2 = Math.floor( Math.random() * (100) );
	$('#contactform #math1').text($math1);
	$('#contactform #math2').text($math2);
	var $mathsum = $math1 + $math2;
	$('#contactform a#formsend').click(function(){ 
		var $name 	= $('#name').val();
		var $email 	= $('#email').val();
		var $subject = $('#subject').val();
		var $message = $('#message').val();
		var $confirm = $('#confirm').val();
		var $contactemail = $('#contactemail').val();
		if($name != '' && $name.length < 3){ $nameshort = true; }else{ $nameshort = false; }
		if($name != '' && $name.length > 30){ $namelong = true; }else{ $namelong = false; }
		if($email != '' && checkemail($email)){ $emailerror = true; }else{ $emailerror = false; }
		if($subject != '' && $subject.length < 3){ $subjectshort = true; }else{ $subjectshort = false; }
		if($subject != '' && $subject.length > 100){ $subjectlong = true; }else{ $subjectlong = false; }
		if($message != '' && $message.length < 3){ $messageshort = true; }else{ $messageshort = false; }
		if($confirm != '' && $confirm != $mathsum){ $confirmerror = true; }else{ $confirmerror = false; }
		$('.loading').fadeIn('fast');
		if($name != '' && $nameshort != true && $namelong != true && $email != '' && $emailerror != false && $subject != '' && $subjectshort != true && $subjectlong != true && $message != '' && $messageshort != true && $confirm != '' && $confirmerror != true && $contactemail != ''){ 
			$.post('php/sendmail.php', 
				{contactemail: $contactemail, name: $name, email: $email, subject: $subject, message: $message}, 
				function(data){
					$('.loading').fadeOut('fast');
					$('#contactform').fadeOut();
					$('#name, #subject, #url, #email, #message, #confirm').val('').css({'border':'none'});
					$('#contactform label span').remove();
					$('label.overlabel-apply').show();
					
					$('<div class="box2 ok"><span>Thank you, ' + $name + '! <br />Your message has been send successfully.</span></div>').insertBefore('#contactform');

					$('.box2').delay(5000).fadeOut(1000, function(){ 
						$(this).remove(); 
						$('#contactform').fadeIn();
						$('label.overlabel-apply').fadeIn();
					});
				}
			);
			return false;
		}else{
			$('.loading').fadeOut('fast');
			
			$('<div class="box2 err"><span>Your message has not been send successfully.<br />It was an error on page!</span></div>').insertBefore('#contactform');

			$('.box2').delay(5000).fadeOut(1000, function(){ $(this).remove(); });
			if($name == ''){ 
				$('#name').parent('div').find('label').find('span').remove(); 
				$('#name').parent('div').find('label').append('<span>&laquo; You forgot to enter your name.</span>'); 
			}else if($nameshort == true){ 
				$('#name').parent('div').find('label').find('span').remove(); 
				$('#name').parent('div').find('label').append('<span>&laquo; Entered name must not be shorter than 3 characters.</span>'); 
			}else if($namelong == true){ 
				$('#name').parent('div').find('label').find('span').remove(); 
				$('#name').parent('div').find('label').append('<span>&laquo; Entered name must not be longer than 30 characters.</span>'); 
			}else{ 
				$('#name').parent('div').find('label').find('span').remove(); 
			}
			if($email == ''){ 
				$('#email').parent('div').find('label').find('span').remove(); 
				$('#email').parent('div').find('label').append('<span>&laquo; You forgot to enter your email address.</span>'); 
			}else if($emailerror == false){ 
				$('#email').parent('div').find('label').find('span').remove(); 
				$('#email').parent('div').find('label').append('<span>&laquo; You entered an invalid email address.</span>'); 
			}else{ 
				$('#email').parent('div').find('label').find('span').remove(); 
			}
			if($subject == ''){ 
				$('#subject').parent('div').find('label').find('span').remove(); 
				$('#subject').parent('div').find('label').append('<span>&laquo; You forgot to enter the subject of your message.</span>'); 
			}else if($subjectshort == true){ 
				$('#subject').parent('div').find('label').find('span').remove(); 
				$('#subject').parent('div').find('label').append('<span>&laquo; Entered subject must not be shorter than 3 characters.</span>'); 
			}else if($subjectlong == true){ 
				$('#subject').parent('div').find('label').find('span').remove(); 
				$('#subject').parent('div').find('label').append('<span>&laquo; Entered subject must not be longer than 100 characters.</span>'); 
			}else{ 
				$('#subject').parent('div').find('label').find('span').remove(); 
			}
			if($message == ''){ 
				$('#message').parent('div').find('label').find('span').remove(); 
				$('#message').parent('div').find('label').append('<span>&laquo; You forgot to enter the text of your message.</span>'); 
			}else if($messageshort == true){ 
				$('#message').parent('div').find('label').find('span').remove(); 
				$('#message').parent('div').find('label').append('<span>&laquo; Entered message must not be shorter than 3 characters.</span>'); 
			}else{ 
				$('#message').parent('div').find('label').find('span').remove(); 
			}
			if($confirm == ''){ 
				$('#confirm').parent('div').find('label').find('span').remove(); 
				$('#confirm').parent('div').find('label').append('<span>&laquo; You forgot to fill the confirmation field.</span>'); 
			}else if($confirmerror == true){ 
				$('#confirm').parent('div').find('label').find('span').remove(); 
				$('#confirm').parent('div').find('label').append('<span>&laquo; Entered confirmation value is incorrect.</span>'); 
			}else{ 
				$('#confirm').parent('div').find('label').find('span').remove(); 
			}
			return false;
		}
	});
});



    // test auto-ready logic - call corner before DOM is ready
    $('.roundboxcorner').corner("5px")

