/*!
 * File: custom.js
 * Description: Sets up some custom properties and effects
 */



/*!
 * Simple Javascript Popup.
 * For popup use: 
 *        onClick="return popup(this, 'TITLE')"
 */

function popup(mylink, windowname) {
    if (! window.focus)return true;
        var href;
    if (typeof(mylink) == 'string')
        href=mylink;
    else
        href=mylink.href;
        window.open(href, windowname, 'width=1024,height=768,scrollbars=yes'); //change window size
    return false;
}

/*!
 * JS Fancy Nav
 */

$(document).ready(function() {
	
	
	$("#topnav li").prepend("<span></span>"); //Throws an empty span tag right before the a tag
	
	$("#topnav li").each(function() { //For each list item...
		var linkText = $(this).find("a").html(); //Find the text inside of the a tag
		$(this).find("span").show().html(linkText); //Add the text in the span tag
	}); 
	
	$("#topnav li").hover(function() {	//On hover...
		$(this).find("span").stop().animate({ 
			marginTop: "-40" //Find the span tag and move it up 40 pixels
		}, 250);
	} , function() { //On hover out...
		$(this).find("span").stop().animate({
			marginTop: "0" //Move the span back to its original state (0px)
		}, 250);
	});
    
    if ($.browser.msie && $.browser.version < 7) return; // Don't execute code if it's IE6 or below cause it doesn't support it.
    
      $(".fade").fadeTo(1, 1);
      $(".fade").hover(
        function () {
          $(this).fadeTo("fast", 0.6);
        },
        function () {
          $(this).fadeTo("slow", 1);
        }
    ); 
    
    
    /* initialize prettyphoto */
    $("a[rel^='prettyPhoto']").prettyPhoto({
  		theme: 'light_rounded'
    });
    

	$(".toggle_title").toggle(
		function(){
			$(this).addClass('toggle_active');
			$(this).siblings('.toggle_content').slideDown("fast");
		},
		function(){
			$(this).removeClass('toggle_active');
			$(this).siblings('.toggle_content').slideUp("fast");
		}
	);
    
    
    $('#buttonsend').click( function() {
	
		var name    = $('#contactname').val();
		var subject = $('#contactsubject').val();
		var email   = $('#contactemail').val();
		var message = $('#contactmessage').val();
		
		$('.loading').fadeIn('fast');
		
		if (name != "" && subject != "" && email != "" && message != "")
			{

				$.ajax(
					{
						url: './sendemail.php',
						type: 'POST',
						data: "name=" + name + "&subject=" + subject + "&email=" + email + "&message=" + message,
						success: function(result) 
						{
							$('.loading').fadeOut('fast');
							if(result == "email_error") {
								$('#contactemail').css("border","1px solid #FFB8B8").next('.require').text(' !');
							} else {
								$('#contactname, #contactsubject, #contactemail, #contactmessage').css("border","1px solid #eaeaea").val("");
								$('<div class="success-message">Your message has been sent successfully. Thank you! </div>').insertBefore('#maincontactform');
								$('.success-message').fadeOut(6000, function(){ $(this).remove(); });
							}
						}
					}
				);
				return false;
				
			} 
		else 
			{
				$('.loading').fadeOut('fast');
				if(name == "") $('#contactname').css("border","1px solid #FFB8B8").next('.require').text(' !');
				if(subject == "") $('#contactsubject').css("border","1px solid #FFB8B8").next('.require').text(' !');
				if(email == "" ) $('#contactemail').css("border","1px solid #FFB8B8").next('.require').text(' !');
				if(message == "") $('#contactmessage').css("border","1px solid #FFB8B8").next('.require').text(' !');
				return false;
			}
	});
	
	$('#contactname, #contactsubject, #contactemail,#contactmessage').focus(function(){
		$(this).css({"border":"1px solid #eaeaea"}).next('.require').text(' *');
	});
	
	
});


$(document).ready(function(){
    $("img.serviceicon").fadeTo("fast", 0.4); // This sets the opacity of the thumbs to fade down to 40% when the page loads
    
    $("img.serviceicon").hover(function(){
        $(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
    },function(){
        $(this).fadeTo("slow", 0.4); // This should set the opacity back to 40% on mouseout
    });
    
    $(".portfolio-details").fadeTo("fast", 0.6); // This sets the opacity of the thumbs to fade down to 50% when the page loads
    
    $(".portfolio-details").hover(function(){
        $(this).fadeTo("fast", 1); // This should set the opacity to 90% on hover
    },function(){
        $(this).fadeTo("fast", 0.6); // This should set the opacity back to 50% on mouseout
    });
    
    
    $("img.galimg").fadeTo("fast", 1.0); // This sets the opacity of the thumbs to fade down to 40% when the page loads
    
    $("img.galimg").hover(function(){
        $(this).fadeTo("normal", 0.5); // This should set the opacity to 50% on hover
    },function(){
        $(this).fadeTo("slow", 1.0); // This should set the opacity back to 100% on mouseout
    });
    
    $(".ssszicon").fadeTo("fast", 0.5); // This sets the opacity of the thumbs to fade down to 50% when the page loads
    
    $(".ssszicon").hover(function(){
        $(this).fadeTo("normal", 0.9); // This should set the opacity to 90% on hover
    },function(){
        $(this).fadeTo("slow", 0.5); // This should set the opacity back to 50% on mouseout
    });
});



$(function() {
    /* JS SCROLL */
    
	$(window).scroll(function() {
		if($(this).scrollTop() != 0) {
			$('#toTop').fadeIn();	
		} else {
			$('#toTop').fadeOut();
		}
	});
 
	$('#toTop').click(function() {
		$('body,html').animate({scrollTop:0},800);
	});
    
    /* JS SLIDE */
    
    $('.SlideTab').tabSwitch('create',{width: 940, height: 900});
    		$('.tabSelect').click(function(e){
    			$('.SlideTab').tabSwitch('moveTo',{index: parseInt($(this).attr("rel"))});
    			e.preventDefault();
    		});
    		$('.servicetab').click(function(e){
    			$('.SlideTab').tabSwitch('moveStep',{step: parseInt($(this).attr("rel"))});
    			e.preventDefault();
    		});	
});
