$(document).ready(function() {

/*
//jump to the top hover flip image 
	$(".jump-top").live("mouseover", function(){
		$(".jump-top-image").html("<img src='../images/Arrow-hover.png' alt='jump-to-top'/>")
	});
		
//jump to the top back to orginal state	
	$(".jump-top").live("mouseout", function(){
		$(".jump-top-image").html("<img src='../images/Arrow.png' alt='jump-to-top'/>")
	});
*/

// jump to the top

	$(".jump-top").click( function(){
		$( 'html, body' ).animate( { scrollTop: 0 }, 'slow' );
	});
	
	$(".jump-top").live("click", function(){
		$('html, body').animate({scrollTip: 0}, 'slow');
	})


		$(".jump-top-image").bind("click", function(){
		$('html, body' ).animate( { scrollTop: 0 }, 'slow' );
		return false;
	});

		
//print the page
	$(".actionPrint").bind("click", function(){
		window.print();
		return false;
	});
	
//email the page
	$(".actionEmail").bind("click", function(){
		$('#emailPopup').show();		
	});
	$('#emailPopup .send').click(function(){
		data = $('#emailPopupForm').serialize();
		$.post('/sendmail.php', data , function(){
			$('#emailPopup').hide();
		})
		return false;
	});
	$('#emailPopup .cancel').click(function(){
		$('#emailPopup').hide();
		return false;
	})
	
	$('#footer .actionFTP').click(function(){
		$('#ftpPopup').show();
	});
	
	
	$('#ftpPopup .send').click(function(){
		$('#ftpPopupForm').submit();
	});
	
	$('#ftpPopup .cancel').click(function(){
		$('#ftpPopup').hide();
		return false;
	});
	
	
	
//  PNG Fix for Old IE Browsers
	$(document).supersleight({shim: 'http://impress-print.serveftp.com/impress/blank.gif'});
	
// Sidemenu Slider controller
/*
	$(document).bind("scroll", function(e) {
		var offset = ( $('#header').height() ) + ( $('#banner').height() );
		var maxoffset = ( $('#content').height() - $('#sidemenu').height() );
		var htmloffset = $('html').scrollTop();
		if (htmloffset > offset) {
			var diff = htmloffset - offset;
			if (diff < maxoffset) {
				$('#sidemenu').animate({"top": diff + "px"},{duration: 100, queue:false});
			} else {
				$('#sidemenu').animate({"top": maxoffset + "px"},{duration: 100, queue:false});
			}
		} else {
			$('#sidemenu').animate({"top": "0px"},{duration: 100, queue:false});
		}
	});
*/
	
// Top Menu navigation
/*
	$('ul.sf-menu').superfish({
			delay		: 0,								// one second delay on mouseout 
			pathClass	: 'current',						// Highlight current location
			animation	: {opacity:'show',height:'show'},	// fade-in and slide-down animation 
			speed		: 'fast',							// faster animation speed 
			autoArrows	: false,							// disable generation of arrow 
			dropShadows	: false								// disable drop shadows				
	});
*/	

// Page indication on the Sidemenu
	var page = $('body').attr("vlink");
	$('#sidemenu .' + page).addClass("active");
	$('#sidemenu .' + page + " a ").addClass("active");
	
// Page indication on the Top Menu
	var menu = $('body').attr("link");
	$('.sf-menu .'+menu).addClass("active");
	//$("#logo").attr("src","/images/logo-" + menu + ".png");

	
// Home page button rollovers
/*
	$('.design-button').hover(function() {
		$('#banner-big .image').attr("src","images/design_image.png");
		$('#banner-big .big_logo').attr("src","Design/images/logo.png");
        $('#banner-big .menuswap').load("Design/sidemenu.php", function(){
            $('#sidemenu').attr('id','areamenu');
            $('#areamenu').find('img').each(function(){
                var t = "Design/" + $(this).attr('src')
                $(this).attr('src',t)
            });
        });
	});
	$('.print-button').hover(function() {
		$('#banner-big .image').attr("src","images/print_image.jpg");
		$('#banner-big .big_logo').attr("src","Print/images/logo.png");
        $('#banner-big .menuswap').load("Print/sidemenu.php", function(){
            $('#sidemenu').attr('id','areamenu');
            $('#areamenu').find('img').each(function(){
                var t = "Print/" + $(this).attr('src')
                $(this).attr('src',t)
            });
        });
	});
	$('.web-button').hover(function() {
		$('#banner-big .image').attr("src","images/web_image.png");
		$('#banner-big .big_logo').attr("src","Web/images/logo.png");
        $('#banner-big .menuswap').load("Web/sidemenu.php", function(){
            $('#sidemenu').attr('id','areamenu');
            $('#areamenu').find('img').each(function(){
                var t = "Web/" + $(this).attr('src')
                $(this).attr('src',t)
            });
        });
	});
	$('.impress-button').hover(function() {
		$('#banner-big .image').attr("src","images/design_image.png");
		$('#banner-big .big_logo').attr("src","images/logo.png");
		$('#banner-big .menuswap').load("AboutUs/sidemenu.php", function(){
            $('#sidemenu').attr('id','areamenu');
            $('#areamenu').find('img').each(function(){
                var t = "AboutUs/" + $(this).attr('src')
                $(this).attr('src',t)
            });
        });
	});
*/

// Menu Rollover for Services

	$('.design-menu-rollover').hover(
		function() {$('.services-menu').css({"background-position":"0 -153px"})},
		function() {$('.services-menu').css({"background-position":"0 0"})}
	);	
	$('.print-menu-rollover').hover(
		function() {$('.services-menu').css({"background-position":"0 -305px"})},
		function() {$('.services-menu').css({"background-position":"0 0"})}
	);	
	$('.web-menu-rollover').hover(
		function() {$('.services-menu').css({"background-position":"0 -457px"})},
		function() {$('.services-menu').css({"background-position":"0 0"})}
	);
	
	//carosel
	
	//$("div.foo").carousel({dispItems:3});
	//$("div.foo").carousel();

	
	// portfolio carousel
	
	
    if (!$('div.portfolio').hasClass("js")) {
        $("div.portfolio").carousel({
            dispItems:1,
			pagination: true,
            prevBtn: "<div></div>",
            nextBtn: "<div></div>",
            equalWidths: "false"
        });
    }
	
//Form Validation and ajax submit for contact form on contact page.

$("#contactForm").validate({
   submitHandler: function(form) {
   $.ajax({
			type: "POST",
			url: "../sendemail.php",
			data: $("#contactForm").serialize(),
			success: function(){
				$('.text #form').fadeOut("slow");
				$('.text').append("<div>Form Submitted Successfully</div>");
			}
		});
   }
})

	//Form Validation for Send Link to Friend and ajax submit
	$("#friend").validate({
		submitHandler: function(form) {
			$.ajax({
				type: "POST",
				url: "../sendfriend.php",
				data: $("#friend").serialize(),
				success: function(){
				$('#friendlightbox').fadeOut("slow");
				$('#whiteout').fadeOut("slow");
				}
			});
		}
	});
	
	
	//Form Validation and ajax submit for contact form on side of page

$("#mainContactForm").validate({
   submitHandler: function(form) {
   $.ajax({
			type: "POST",
			url: "../sendemail.php",
			data: $("#mainContactForm").serialize(),
			success: function(){
				//$("#mainContactForm").slideUp("slow" ,function(){
				$("#contactFormContainer").animate( { left:"-460px"}, 1000 );
				//});
			}
		});
   }
})
	
	/*
	$("#contactLink").click(function(){
        if ($("#mainContactForm").is(":hidden")){      
			$("#contactFormTable").animate( { left:"0px"}, 1000, function(){
			$("#mainContactForm").animate({width:"446px"}, 1000)
			});
		} else{
			$("#contactFormTable").animate({width:"34px"}, 1000, function(){
			$("#mainContactForm").css({'display':'none'})
			$("#contactFormTable").animate( { left:"0px"}, 1000 );   
		})
		}
    });
	
	*/
	
	$("#contactLink").click(function(){
		
		
//		if($("#contactFormContainer").is(":-450px"))

        if ( $("#contactFormContainer").css("left") == "-460px" )
        {
			$("#contactFormContainer").animate( {left:"0px"}, "slow")
		} else {
            $("#contactFormContainer").animate( {left:"-460px"}, "slow")
		}
			
		
	});

	
     
            
// Lightbox popup
	$('.lightbox').bind("click", function(){        
        var g = $(this).children('img').attr("gallery");
        var w = (( $(window).width() ) - $('#lightbox').width() ) / 2;
        var h = ((( $(window).height() - 75 )) - $('#lightbox').height() ) / 2;
        $('#lightbox').css({"top": h, "left": w});

        $.ajax({
            type: "GET",
            url: "../lightbox.php",
            data: "gallery_id="+g,
            success: function(html){
                $('#lightbox').html(html);

                $('#lightbox .cache').hide();

                if ($.browser.msie) {
                    $('#whiteout').show();
                    $('#lightbox').show();
                        carousel();
                } else {
                	$('#whiteout').fadeIn(1000, function(){
                        $('#lightbox').fadeIn(1000, function(){
                            carousel();
                        });
                    });
                }

                $('.lightbox-close').bind("click", function(){
                    if ($.browser.msie) {
                        $('#lightbox').hide();
                        $('#whiteout').hide();
                        $('#lightbox .cache').show();
                    } else {
                        $('#lightbox').fadeOut("1000", function(){
                            $('#whiteout').fadeOut("1000", function(){
                                $('#lightbox .cache').show();
                            });
                        });
                    }
              	});

        //expand image
                $("div.foo img").bind("click", function(e){
            		var image_source = jQuery(this).attr("img");
                    var image_description = jQuery(this).attr("alt");
                    //$(".big-image").text("source :" + image_source + " alt :" + image_description);

            		$(".big-image").html('<img style="position:absolute;" src=' + image_source + ' alt=' + image_description + ' />');

            		var width = $(".big-image img").width();
            		var height =  $(".big-image img").height();
            		var max_width = $(".big-image").width();
                    var max_height = $(".big-image").height();
                	var height_ratio = ((height) / (max_height));
                	var width_ratio = ((width) / (max_width));
                    //$(".big-image").text("width :" + width_ratio + " height ratio :" + height_ratio);

            		if(width_ratio > 1 || height_ratio > 1){
                        if(width_ratio > height_ratio){
            				var wi = ((width) / (width_ratio));
                        	$(".big-image img").attr("width",wi);
            			} else {
                        	var he = ((height) / (height_ratio));
            				$(".big-image img").attr("height",he);
                        }
                    }

            		//$(".big-image").text("width :" + he + " height ratio :" + wi);
            		var w = (( $('.big-image').width() ) - $(".big-image img").width() ) / 2;
                    var h = (( $('.big-image').height() ) - $(".big-image img").height() ) / 2;
                    $(".big-image img").css({"top": h, "left": w});
                });
            }
        });        
	});	
	
	// send to friend lightbox
	
		$('.emaillogo').bind("click", function(){
		$('#whiteout').fadeIn(1000, function(){
			var w = (( $(window).width() ) - $('#friendlightbox').width()  ) / 2;
			var h = (( $(window).height() ) - $('#friendlightbox').height() ) / 2;
			$('#friendlightbox').css({"top": h, "left": w});
			if ($.browser.msie) {
                $('#whiteout').show();
                $('#friendlightbox').show();
			} else {
				$('#friendlightbox').fadeIn(1000);
			}
		});
	});
	
	$('.friendlightbox-close').bind("click", function(){
		if ($.browser.msie) {
            $('#friendlightbox').hide();
            $('#whiteout').hide();
		} else {
			$('#friendlightbox').fadeOut("1000", function(){
			$('#whiteout').fadeOut(1000);
			});
		}
	});
});

function carousel() {
    if (!$('div.foo').hasClass("js")) {
        $("div.foo").carousel({
            dispItems:4,
            prevBtn: "<div></div>",
            nextBtn: "<div></div>",
            equalWidths: "false"
        });
    }
}

function newcarousel() {
    $('#carousel').carousel('#previous', '#next');
}

//function setPage(section,page)
// sets the pages logo depending on var sec
// sets the section indication depending on var sec
// sets the var page as active in sidemenu
/*
function setPage(sec, page){

	// Page indication on the Sidemenu
	$('#sidemenu .' + page).addClass("active");
	$('#sidemenu .' + page + " a ").addClass("active");
	
	// Page indication on the Top Menu
	$('.sf-menu .'+ sec).addClass("active");

	//set logo depending on section.
	//$("#logo").attr("src","./images/logo-" + sec + ".png");
}*/
