document.documentElement.className += ' js';

(function($){
    $(document).ready(function(){
        //open external links in a new window
        $('a[rel*="external"]').attr('target', '_blank');
        
      //more images
        $('ul#more-images a').each(function(){
            var $this = $(this), $href = this.href;
            
            $this.click(function(){
                $('a#product-image img').attr('src', $href);
                $('a#product-image').attr('href', $href);
                $('a#product-image img').attr('width',320);
                $('a#product-image img').attr('height',320);
                return false;
            });
        });
        
        //partners filter
        var sel = $('select#partners_filter'), parters = $('ul#partners');
        
        sel.change(function(){
            $('li', parters).hide();
            $('li.' + $(this).val(), parters).show();
        });
        
        $('.price-box .radio').click(function(){
            $('input:radio').removeAttr('checked');
            $('button.selected').removeClass('selected');
            $(this).parent().siblings('button.button').addClass('selected');
            $(this).attr("checked", true);
            
        });
        
        function mycarousel_initCallback(carousel){
            //            jQuery('.application-sec li').bind('click', function() {
            //                carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
            //                return false;
            //            });
            $('.application-sec ul a').bind('click', function(){
                $('.application-sec li').removeClass('active');
                carousel.scroll($.jcarousel.intval($(this).text()));
                $(this).parent().addClass('active');
                return false;
            });
            
            jQuery('#mycarousel-next').bind('click', function(){
                carousel.next();
                return false;
            });
            
            jQuery('#mycarousel-prev').bind('click', function(){
                carousel.prev();
                return false;
            });
        };
        //        jQuery("#mycarousel").jcarousel({
        //            scroll: 1,
        //            initCallback: mycarousel_initCallback,
        //            // This tells jCarousel NOT to autobuild prev/next buttons
        //            buttonNextHTML: null,
        //            buttonPrevHTML: null
        //        });
        
        //        $('.more-views a').each(function(){
        //            var $this = $(this), $href = this.href;
        //            return false;
        //        });
        
        $('.cms-applications #promo-banners').cycle({
            timeout: 5000
        })
        
        //open images in a modal box 
        $('a[rel*="fancybox"]').fancybox({
            'overlayShow': false,
            'zoomSpeedIn': 300,
            'zoomSpeedOut': 300
        });
        
        //product images carousel
        
        $('.more-views ul').jcarousel({});
        
        $('ul.take-tour').jcarousel({
            scroll: 1,
            initCallback: mycarousel_initCallback
        });
        
        
        var $tooltip = $('<div id="tooltip"><div></div></div>').appendTo('body').hide(), $tooltipBody = $('div', $('#tooltip')[0]);
        //create tooltip
        //application page tooltip
        $('#feature-list strong').each(function(){
            var $this = $(this), $title = this.title;
            
            $this.hover(function(e){
                if ($title) {
                    $this.attr('title', '');
                    $tooltipBody.text($title);
                    $tooltip.removeClass().stop().fadeTo(200, 1);
                }
            }, function(){
                $this.attr('title', $title);
                $tooltip.stop().fadeOut(200, function(){
                    $tooltip.removeClass();
                    $tooltipBody.text('');
                });
            });
            
            $this.mousemove(function(e){
                $tooltip.css({
                    'top': e.pageY,
                    'left': e.pageX + 15
                });
                if (e.pageY + $tooltip.outerHeight() >= document.body.scrollHeight) {
                    $tooltip.addClass('alt').css({
                        'top': e.pageY - $tooltip.outerHeight()
                    });
                }
            });
        });
        
        //products range slide show
        
        $('ul.product-range').jcarousel({
            'scroll': 1,
            'auto': 3,
            'wrap': 'last'
            //        	'scroll': 1,
            //        	'auto': 3,
            //        	'wrap': 'last',
            //        	'initCallback': mycarousel_initCallback
        
        });
        
        
        //sector select tooltip
        
        $('.sectors-selector strong').each(function(){
            var $this = $(this), $title = this.title;
            
            $this.hover(function(e){
                if ($title) {
                    $this.attr('title', '');
                    $tooltipBody.text($title);
                    $tooltip.removeClass().stop().fadeTo(200, 1);
                }
            }, function(){
                $this.attr('title', $title);
                $tooltip.stop().fadeOut(200, function(){
                    $tooltip.removeClass();
                    $tooltipBody.text('');
                });
            });
            
            $this.mousemove(function(e){
                $tooltip.css({
                    'top': e.pageY,
                    'left': e.pageX + 15
                });
                if (e.pageY + $tooltip.outerHeight() >= document.body.scrollHeight) {
                    $tooltip.addClass('alt').css({
                        'top': e.pageY - $tooltip.outerHeight()
                    });
                }
            });
        });
        
        //price plans page tooltip
        
        $('.priceplan-content strong').each(function(){
            var $this = $(this), $title = this.title;
            
            $this.hover(function(e){
                if ($title) {
                    $this.attr('title', '');
                    $tooltipBody.text($title);
                    $tooltip.removeClass().stop().fadeTo(200, 1);
                }
            }, function(){
                $this.attr('title', $title);
                $tooltip.stop().fadeOut(200, function(){
                    $tooltip.removeClass();
                    $tooltipBody.text('');
                });
            });
            
            $this.mousemove(function(e){
                $tooltip.css({
                    'top': e.pageY,
                    'left': e.pageX + 15
                });
                if (e.pageY + $tooltip.outerHeight() >= document.body.scrollHeight) {
                    $tooltip.addClass('alt').css({
                        'top': e.pageY - $tooltip.outerHeight()
                    });
                }
            });
        });
        
       
        
// software  filter
//        $("#prodGrid li."+$("input.type_check").attr('id')).addClass('type_hidden');
//		$("#prodGrid li."+$("input.type_check").attr('id')).slideUp();
//		$("#prodGrid li."+$("input.start_check").attr('id')).addClass('type_hidden');
//		$("#prodGrid li."+$("input.start_check").attr('id')).slideUp();
//		$("#prodGrid li."+$("input.place_check").attr('id')).addClass('type_hidden');
//		$("#prodGrid li."+$("input.place_check").attr('id')).slideUp();
//
//		$("input.custom-checkbox").click(function() {
//		$("input.custom-checkbox").attr('checked');
//			if($(this).is(':checked')) {
//				$("#prodGrid li."+$(this).attr('id')).removeClass('hidden');
//				
//			} else {
//				$("#prodGrid li."+$(this).attr('id')).addClass('hidden');
//				
//			}
//		});

        //$('.options-list > li:first-child').addClass('first-item');
		
		//checkout form
    	var cf = $('form#co-billing-form').addClass('dev'),
    		personal = $('ul.customer-select li').eq(0).children(':radio'),
    		education = $('ul.customer-select li').eq(1).children(':radio'),
    		business = $('ul.customer-select li').eq(2).children(':radio'); 
    		
//    		//hide all li-s
    		$('#custom-fields-aitoc li', cf).hide();
    		$('ul.customer-select li', cf).show(); 
//    		$('select#billing-address-select', cf).show(); 
    		
    		$('ul.customer-select :radio').bind('change click', function(){
    			$('#custom-fields-aitoc li', cf).hide();
    			$('fieldset:first li.control li,ul.customer-select li', cf).show();
    			$('input, textarea, select', cf).removeClass('required-entry validate-email');
    			
    			billingForm = new VarienForm('co-billing-form', true);
    			billingForm.validator.reset();
    			$('.validation-advice', cf).remove();
    		});
    		
         $('input[name="billing[aitoc_checkout_207]"]').parents('div.field').prepend('<label class="desc" for="billing:aitoc_checkout_207">If Not Limited or PLC? &#45; Please Provide Names and Current Home Addresses of the Owners of the Business.</label>');
         $('input[name="billing[aitoc_checkout_191]"]').parents('div.field').prepend('<label class="desc" for="billing:aitoc_checkout_191"><strong>3. If less than 3 Years,</strong> Please provide previous address.</label>');
         $('input[name="billing[aitoc_checkout_185]"]').parents('div.field').prepend('<label class="desc" for="billing:aitoc_checkout_185"><strong>2. Home</strong></label><br/>');
         $('input[name="billing[aitoc_checkout_220]"]').parents('div.field').prepend('<label class="desc" for="billing:aitoc_checkout_220"><strong> Company Directors: </strong></label><br/>');
  
    		//personal
    		personal.bind('click change', function(){
    			if($(this).is(':checked')){
    				$.each([
    					'select[name="billing[aitoc_checkout_180]"]',
    					'input[name="billing[aitoc_checkout_181]"]',
    					'input[name="billing[aitoc_checkout_182]"]',
    					'input[name="billing[aitoc_checkout_183]"]',
    					'select[name="billing[aitoc_checkout_184]"]',
    					'input[name="billing[aitoc_checkout_185]"]',
    					'input[name="billing[aitoc_checkout_186]"]',
    					'input[name="billing[aitoc_checkout_187]"]',
    					'input[name="billing[aitoc_checkout_188]"]',
    					'input[name="billing[aitoc_checkout_189]"]',
    					'input[name="billing[aitoc_checkout_190]"]',
    					'input[name="billing[aitoc_checkout_191]"]',
    					'input[name="billing[aitoc_checkout_192]"]',
    					'input[name="billing[aitoc_checkout_193]"]',
    					'input[name="billing[aitoc_checkout_194]"]',
						'input[name="billing[aitoc_checkout_195]"]',
						'select[name="billing[billing-address-select]"]',
//						'input[name="billing[firstname]"]',
//						'input[name="billing[lastname]]"]',
//						'input[name="billing[company]"]',
//						'input[name="billing[street1]]"]',
//						'input[name="billing[street2]]"]',
//						'select[name="billing[region_id]"]',
//						'input[name="billing[postcode]]"]',
//						'select[name="billing[country_id]]"]',
//						'input[name="billing[telephone]]"]',
//						'input[name="billing[fax]"]',
//						'input[name="billing[telephone]]"]',
    					'select[name="billing[aitoc_checkout_196]"]'
    				], function(index, value){
    					$(value).addClass('required-entry').parents('li').show();
    				});
    				
    				$('input[name="billing[aitoc_checkout_190]"]').addClass('required-entry validate-email').parents('li').show();
    				
    			}
    		});
    		
    		
    		
    		//business
    		business.bind('click change', function(){
    			if($(this).is(':checked')){
    				$.each([
    					'input[name="billing[aitoc_checkout_197]"]',
    					'input[name="billing[aitoc_checkout_198]"]',
    					'input[name="billing[aitoc_checkout_199]"]',
    					'select[name="billing[aitoc_checkout_200]"]',
    					'input[name="billing[aitoc_checkout_201]"]',
    					'input[name="billing[aitoc_checkout_202]"]',
    					'input[name="billing[aitoc_checkout_203]"]',
    					'input[name="billing[aitoc_checkout_204]"]',
    					'input[name="billing[aitoc_checkout_205]"]',
    					'input[name="billing[aitoc_checkout_207]"]',
    					'input[name="billing[aitoc_checkout_208]"]',
    					'input[name="billing[aitoc_checkout_209]"]',
    					'input[name="billing[aitoc_checkout_210]"]',
						'input[name="billing[aitoc_checkout_211]"]',
						'input[name="billing[aitoc_checkout_212]"]',
    					'input[name="billing[aitoc_checkout_213]"]',
    					'input[name="billing[aitoc_checkout_214]"]',
    					'input[name="billing[aitoc_checkout_215]"]',
    					'input[name="billing[aitoc_checkout_216]"]',
    					'input[name="billing[aitoc_checkout_217]"]',
    					'input[name="billing[aitoc_checkout_218]"]',
    					'input[name="billing[aitoc_checkout_219]"]',
    					'input[name="billing[aitoc_checkout_220]"]',
    					'input[name="billing[aitoc_checkout_221]"]',
    					'input[name="billing[aitoc_checkout_222]"]',
						'input[name="billing[aitoc_checkout_223]"]',
						'input[name="billing[aitoc_checkout_224]"]',
						'select[name="billing[billing-address-select]"]',
//						'input[name="billing[firstname]"]',
//						'input[name="billing[lastname]]"]',
//						'input[name="billing[company]"]',
//						'input[name="billing[street1]]"]',
//						'input[name="billing[street2]]"]',
//						'select[name="billing[region_id]"]',
//						'input[name="billing[postcode]]"]',
//						'select[name="billing[country_id]]"]',
//						'input[name="billing[telephone]]"]',
//						'input[name="billing[fax]"]',
//						'input[name="billing[customer_password]"]',
//						'input[name="billing[firstname]"]',
//						'input[name="billing[lastname]]"]',
						'input[name="billing[aitoc_checkout_225]"]'
    				], function(index, value){
    					$(value).addClass('required-entry').parents('li').show();
    				});
    				
    				$('input[name="billing[aitoc_checkout_203]"]').addClass('required-entry validate-email').parents('li').show();
    				$('input[name="billing[aitoc_checkout_206][]"]').parents('li').show();
    			}
    		});
    		
    		
    		//education
    		education.bind('click change', function(){
    			if($(this).is(':checked')){
    				$.each([
    					'input[name="billing[aitoc_checkout_226]"]',
    					'input[name="billing[aitoc_checkout_227]"]',
    					'input[name="billing[aitoc_checkout_228]"]',
    					'input[name="billing[aitoc_checkout_229]"]',
    					'input[name="billing[aitoc_checkout_230]"]',
    					'input[name="billing[aitoc_checkout_231]"]',
    					'input[name="billing[aitoc_checkout_232]"]',
    					'input[name="billing[aitoc_checkout_233]"]',
    					'input[name="billing[aitoc_checkout_234]"]',
    					'input[name="billing[aitoc_checkout_235]"]',
    					'select[name="billing[aitoc_checkout_236]"]',
    					'input[name="billing[aitoc_checkout_237]"]',
    					'textarea[name="billing[aitoc_checkout_238]"]',
    					'input[name="billing[aitoc_checkout_239]"]',
//    					'input[name="billing[city]"]',
//						'input[name="billing[firstname]"]',
//						'input[name="billing[lastname]]"]',
//						'input[name="billing[company]"]',
//						'input[name="billing[street1]]"]',
//						'input[name="billing[street2]]"]',
//						'input[name="billing[city]]"]',
//						'select[name="billing[region_id]"]',
//						'input[name="billing[postcode]]"]',
//						'input[name="billing[country_id]]"]',
//						'input[name="billing[telephone]]"]',
//						'input[name="billing[fax]"]',
//    					'input[name="billing[customer_password]"]',
//						'input[name="billing[firstname]"]',
						'select[name="billing[billing-address-select]"]',
						'input[name="billing[aitoc_checkout_240]"]'
					], function(index, value){
    					$(value).addClass('required-entry').parents('li').show();
    				});
    				
    				$('input[name="billing[aitoc_checkout_233]"]').addClass('required-entry validate-email').parents('li').show();
    			
    			}
    		});
    		
//    		
    		//education		
//    		education.bind('click change', function(){
//    			if ($(this).is(':checked')) {
//    				for(var i=1; i<13; i++) {
//    					if(i<=9) {
//    						$('input[name="billing[aitoc_checkout_99' + i + ']"]').addClass('required-entry').parents('li').show();
//    					} else if(i==10) {
//    						$('input[name="billing[aitoc_checkout_1000]"]').addClass('required-entry').parents('li').show();
//    					} else {
//    						$('input[name="billing[aitoc_checkout_10' + i + ']"]').addClass('required-entry').parents('li').show();
//    					}
//    					
//    				}
//    				
//    				$('select[name="billing[aitoc_checkout_993]"], select[name="billing[aitoc_checkout_1002]"]').addClass('required-entry').parents('li').show();
//    			}
//    		});
//    		
//    		//business
//    		business.bind('click change', function(){
//    			if ($(this).is(':checked')) {
//    				for(var i=5; i<51; i++) {
//    					$('input[name="billing[aitoc_checkout_10' + (i<=9 ? 0 : '') + i + ']"]').addClass('required-entry').parents('li').show();
//    				}
//    				$('input[name="billing[aitoc_checkout_1011]"], input[name="billing[aitoc_checkout_1030]"]').addClass('validate-email').parents('li').show();
//    				$('select[name="billing[aitoc_checkout_1004]"]').addClass('required-entry').parents('li').show();
//    			}
//    		});
        
    });
    
    
})(jQuery);

