/* 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);
  });
			
/* 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: 500,
			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="950" height="500"><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="950" height="500" 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 $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; }

        $('.loading').fadeIn('fast');
        if ($name != '' && $nameshort != true && $namelong != true && $email != '' && $emailerror != false && $subject != '' && $subjectshort != true && $subjectlong != true && $message != '' && $messageshort != true && $contactemail != '') {
            $.ajax({

                type: "POST",
                url: "/Contact/SendContact",
                data: "name=" + $name + "&email=" + $email + "&message=" + $message + "&subject=" + $subject,
                success: function (result) {
                    $('.loading').fadeOut('fast');
                    $('#contactform').fadeOut();
                    $('#name, #subject, #url, #email, #message').val('').css({ 'border': 'none' });
                    $('#contactform label span').remove();
                    $('label.overlabel-apply').show();

                    $('<div class="box2 ok"><span>Merci, ' + $name + '! <br />Votre message a &eacute;t&eacute; envoy&eacute;.</span></div>').insertBefore('#contactform');

                    $('.box2').delay(5000).fadeOut(1000, function () {
                        $(this).remove();
                        $('#contactform').fadeIn();
                        $('label.overlabel-apply').fadeIn();
                    });

                },
                error: function (req, status, error) {
                    $('<div class="box2 err"><span>Attention,<br />Votre message n\'a pas &eacute;t&eacute; envoy&eacute;, une erreur s\'est produite !</span></div>').insertBefore('#contactform');
                }
            });

            return false;
        }
        else {
            $('.loading').fadeOut('fast');

            $('<div class="box2 err"><span>Attention,<br />Il y a une erreur dans le formulaire !</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; Vous avez oubli&eacute; d\'entrer votre nom.</span>');
            } else if ($nameshort == true) {
                $('#name').parent('div').find('label').find('span').remove();
                $('#name').parent('div').find('label').append('<span>&laquo; Votre nom doit contenir plus de 3 caract&egrave;res.</span>');
            } else if ($namelong == true) {
                $('#name').parent('div').find('label').find('span').remove();
                $('#name').parent('div').find('label').append('<span>&laquo; Votre nom ne doit pas contenir plus de 30 caract&egrave;res.</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; Vous avez oubli&eacute; d\'entrer votre adresse email.</span>');
            } else if ($emailerror == false) {
                $('#email').parent('div').find('label').find('span').remove();
                $('#email').parent('div').find('label').append('<span>&laquo; Votre adresse email est invalide.</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; Vous avez oubli&eacute; d\'entrer le sujet de votre message.</span>');
            } else if ($subjectshort == true) {
                $('#subject').parent('div').find('label').find('span').remove();
                $('#subject').parent('div').find('label').append('<span>&laquo; Votre sujet doit contenir plus de 3 caract&egrave;res.</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; Vous avez oubli&eacute; d\'entrer votre message.</span>');
            } else if ($messageshort == true) {
                $('#message').parent('div').find('label').find('span').remove();
                $('#message').parent('div').find('label').append('<span>&laquo; Votre message  doit contenir plus de 3 caract&egrave;res.</span>');
            } else {
                $('#message').parent('div').find('label').find('span').remove();
            }
            return false;
        }
    });
});



    // test auto-ready logic - call corner before DOM is ready
    $('.roundboxcorner').corner("5px")

