jQuery(document).ready(function(){
	
    if( jQuery('body.browserInternetExplorer7').length > 0 || jQuery('body.browserInternetExplorer8').length > 0 ) {
       	jQuery('body').find('h2').each(function() {
            jQuery(this).html( '<span class="before"></span>'+ jQuery(this).html()  + '<span class="after"></span>');
        });
    }

    if ( typeof jQuery.popupWindow == 'object' ) {
        jQuery('.help-popup').popupWindow({
            centerBrowser:1
        });
    }

    if ( jQuery('#banner').length > 0 ) { jQuery('html').addClass('banner'); }

    jQuery('select[name="source"]').bind('click, change', function()
    {
        if( jQuery(this).find('option:selected').val() == 'Other' ) {
            jQuery('#source_other, input[name="source_other"]').removeClass('hide');
        }
        else {
            jQuery('#source_other, input[name="source_other"]').addClass('hide');
        }
    });
    
    if( jQuery('#knowledge-base #numbers-page-nav a:first-child').length > 0 ) {
    	jQuery('#knowledge-base #numbers-page-nav a:first-child').remove();
    	jQuery('#knowledge-base #numbers-page-nav').prepend(1);
    }

    //contentPosition = jQuery('#content').position();
    //jQuery("html").animate({ scrollTop: contentPosition.top }, "slow");

    //jQuery('div#banner').before('<div id="banner-nav"><ul></ul></div>').cycle({
    jQuery('div#banner').cycle({
        fx: 'fade',
        speed: 1,
        timeout: 6000,
        pause: 1
    });
    
    $('#whois input[type="submit"]').click(function() {
    	domain = $('#domain-name').val();
    	$.ajax({
            type: "POST",
            dataType: 'html',
            url: "/jsActions.php",
            data: "action=whois&" + $('#whois').serialize(),
            success: function(data) {
                $('#log_res').html(data);
            }
        });
        return false;
    });
    /*pager: '#banner-nav ul',
        pagerEvent: 'mouseover',
        pauseOnPagerHover: 1,
        //fastOnEvent: 1, removed as it was lagging and showing content behind the images
        allowPagerClickBubble: true,
        // callback fn that creates a thumbnail to use as pager anchor
        pagerAnchorBuilder:	function(idx, slide) {
            if(idx == 0)
            {
                link = '/';
                txt	 = 'home';
            }
            else if (idx == 1)
            {
                link = '/about-us';
                txt	 = 'about us';
            }
            else if (idx == 2)
            {
                link = '/portfolio';
                txt	 = 'our portfolio';
            }
            else if (idx == 3)
            {
                link = '/contact';
                txt	 = 'contact us';
            }
            else if (idx == 4)
            {
                link = '/the-knowledge-base/';
                txt	 = 'knowledge base';
                //link =  '';
                //txt =  '';
            }

            return '<li class="slide-nav slide-'+ (idx + 1) +'"><a href="'+ link +'">' + txt + '</a></li>';
        }*/

   /* jQuery('#banner-nav a').live('mouseover', function(){
        jQuery('div#banner').cycle('pause');
    }).live('mouseout', function(){
        jQuery('div#banner').cycle('resume');
    });*/


    if ( typeof jQuery.fancybox == 'function' ) {

		jQuery.fn.getTitle = function() {
			var arr = jQuery("a.fancybox");
			jQuery.each(arr, function() {
				var title = jQuery(this).children("img").attr("title");
				jQuery(this).attr('title',title);
			})
		}

		var thumbnails = 'a:has(img)[href$=".bmp"],a:has(img)[href$=".gif"],a:has(img)[href$=".jpg"],a:has(img)[href$=".jpeg"],a:has(img)[href$=".png"],a:has(img)[href$=".BMP"],a:has(img)[href$=".GIF"],a:has(img)[href$=".JPG"],a:has(img)[href$=".JPEG"],a:has(img)[href$=".PNG"]';

		jQuery(thumbnails).not('.portfolio').addClass("fancybox").attr("rel","fancybox").getTitle();
		/**
		 * Allows fancybox to run on dynamic events e.g. content loaaded via Ajax request
		 */
		jQuery(document).ajaxStop(function() { 
			jQuery('a.portfolio, a.fancybox').fancybox({
			    'transitionIn'	 : 'elastic',
			    'transitionOut'	 : 'elastic',
			    'centerOnScroll':  true,
			    'speedIn'		 : 600,
			    'speedOut'		 : 200,
			    'padding'		 : 0,
			    'hideOnContentClick' : true,
			    'cyclic'		 : true,
			    'centerOnScroll' : true,
				'overlayColor'	 : '#000',
				'overlayOpacity' : 0.6,
				'onStart'		 : toast
			});
		});
		
		jQuery('a.portfolio, a.fancybox').fancybox({
		    'transitionIn'	 : 'elastic',
		    'transitionOut'	 : 'elastic',
		    'centerOnScroll':  true,
		    'speedIn'		 : 600,
		    'speedOut'		 : 200,
		    'padding'		 : 0,
		    'hideOnContentClick' : true,
		    'cyclic'		 : true,
		    'centerOnScroll' : true,
			'overlayColor'	 : '#000',
			'overlayOpacity' : 0.6,
			'onStart'		 : toast
		});
    }
    
    function toast() {
    	/*start = 12;
    	perRow = 12;
    	all = false;
    	$.ajax({
            type: "POST",
            dataType: 'json',
            url: "/jsActions.php",
            data: "action=portfolio&start=" + start + '&limit=' + perRow + '&view_all=' + all,
            success: function(data) {
            	//console.log(data);
                if( typeof data.error == 'undefined' ) {
                	$('#portfolio').html(data.html);
                }
            }
        });*/
      //console.log($.fancybox);
    }
    

    jQuery('body').find('tbody.products').each(function() {
        if( jQuery(this).children('tr:eq(5)').length > 0 ) {
            jQuery(this).children('tr:gt(4)').hide();
            jQuery(this).parents('.right_price').find('p.products-show-more').removeClass('hide').html('more quantities');
        }
    });

    jQuery('.products-show-more').click(function() {
        jQuery(this).siblings('table').find('tbody tr:gt(4)').toggle();
        jQuery(this).toggleClass('expand');
        if( jQuery(this).hasClass('expand') ) {
                jQuery(this).html('fewer quantities');
        } else {
                jQuery(this).html('more quantities');
        }
    });
	
	jQuery("#survey input:radio").attr("checked", false);
});

