﻿$(document).ready(function(){
    	
    //apply ifixpng	
    $('.display-s-offer').ifixpng();
    $('.display-out-of-stock').ifixpng();
    $('.item-thumb').ifixpng();
    
    //show submenus
     
    $('#menu li').find('div').hide().end().find('a[@href*=#], a.more').click(function(){        
        var smenu = $(this).next();        
        if(smenu.is(':visible')){
            smenu.slideUp();
        }else{
            smenu.slideDown();
        }
        return false
    });
    
            
    //Image Galery of Products    
    //Modal    
    $('.img-placeholder').each(function(){
        var img = $(this).attr('lowsrc');
        if(img != " " && img != null && img != "undefined" && img != '#' ){
            $(this).css('cursor','pointer').prev('a').addClass('expand');
            $('a.expand').attr({'title':'Click on the image to view a large size version'}).click(function(){return false;});
        }     
    });
    
    $('#box-galery-thumbs a').each(function(i){        
        $(this).click(function(){
            var source = $(this).find('img').attr("src");
            var wide = $(this).attr("href");
            var text = $(this).attr("title");
            if(wide != '' && wide != 'undefined'&& wide != '#' ){
                $('.img-placeholder').attr({'src':source,'alt':text,'lowsrc':wide}).css('cursor','pointer').prev('a').addClass('expand');
                $('a.expand').attr({'title':'Click on the image to view a large size version'}).click(function(){return false;});
            }else{
                $('.img-placeholder').attr({'src':source,'alt':text,'lowsrc':wide}).css('cursor','default').prev('a').removeClass('expand');
            }            
            return false;
        });
    }); 
    
    //Modal    
    $('.img-placeholder').click(function(){
        var img = $(this).attr('lowsrc');
        if(img != '' && img != 'undefined'&& img != '#' ){
            var text = $(this).attr('alt');
            $.modal('<img src='+img+' width="814" height="475" alt='+text+'/><p>'+text+'</p>');
        }
		$('#modalContainer').css({top:'580px',position:'absolute'});
    });
	
    
    // Contact    
    $('.form-contact select').bind('change', function(){
        var subject = $(this).val();
        var para = $('#downThis');
        if(para){
            $(para).remove();
        };
        if(subject == 'catalogue'){
            $('<p id="downThis">You can also <a href="download catalogue in pdf" title="Catalogue in pdf">download catalogue in .pdf(4184kb).</a></p>').insertAfter('div.fr');
        };
    });
    
    
    //Script para alterar titulo Menu About, Menu Sections e Institucional    
    var currentUrl = window.location.href;
    
    //Menu Sections    
    if (currentUrl.indexOf('/services/')!= -1){
        $('ul.sections li a.mn-services').addClass('on');
	}else if (currentUrl.indexOf('/about-arthome/')!= -1){
        $('ul.sections li a.mn-about-artemis').addClass('on');
    }else if (currentUrl.indexOf('/environmental-agenda/')!= -1){
        $('ul.sections li a.mn-environmental-agenda').addClass('on');
    }else if (currentUrl.indexOf('/special-offers/')!= -1){
        $('ul.sections li a.mn-special-offers').addClass('on');
    }else{
		$('ul.sections li a.mn-services').addClass('on');
	}
	
	//Seção Services
    
    if (currentUrl.indexOf('kitchens.html')!= -1){
        $('a.mnl-kitchens').addClass('on');
    }else if(currentUrl.indexOf('bathrooms.html')!= -1){
        $('a.mnl-bathrooms').addClass('on');
    }else if(currentUrl.indexOf('extensions-conversions.html')!= -1){
        $('a.mnl-extensions-conversions').addClass('on');
    }else if(currentUrl.indexOf('flooring.html')!= -1){
        $('a.mnl-flooring').addClass('on');
    }else if(currentUrl.indexOf('general-building.html')!= -1){
        $('a.mnl-general-building').addClass('on');
    }else if(currentUrl.indexOf('heating-systems.html')!= -1){
        $('a.mnl-heating-systems').addClass('on');
    }else if(currentUrl.indexOf('quotation-request.html')!= -1||currentUrl.indexOf('quotation-request-sucess.html')!= -1){
        $('a.mnl-quotation-request').addClass('on');
    }
	
	//Seção ABOUT ARTHOME    
    if (currentUrl.indexOf('about-arthome.html')!= -1){
        $('a.mnl-about').addClass('on');
    }else if(currentUrl.indexOf('contact-us.html')!= -1 || currentUrl.indexOf('contact-us-sucess.html')!= -1){
        $('a.mnl-contact').addClass('on');
    }else if(currentUrl.indexOf('links.html')!= -1){
        $('a.mnl-links-about').addClass('on');
	}else if(currentUrl.indexOf('sitemap.html')!= -1){
        $('a.mnl-sitemap').addClass('on');
	}
	
	//Seção Environmental   
    if (currentUrl.indexOf('ethos.html')!= -1){
        $('a.mnl-ethos').addClass('on');
    }else if(currentUrl.indexOf('insulation.html')!= -1){
        $('a.mnl-insulation').addClass('on');
    }else if(currentUrl.indexOf('renewable-energy-systems.html')!= -1){
        $('a.mnl-renewable-energy-systems').addClass('on');
	}else if(currentUrl.indexOf('solar-water-heating.html')!= -1){
        $('a.mnl-solar-water-heating').addClass('on');
	}
    
    /* ===== sobreposiçõs no Flash ==== */
	if ($('body').hasClass("mod2")||$('body').hasClass("mod3")){
		$('<div id="top-menu-double"></div>').appendTo('div#header');	
	}
	
	//Seção Products
	$('#text-about p:first').css({textIndent:'8px', background:'url(../img/bullet-circle.gif) no-repeat left 6px'});
        
});

// Carrocel

var margin = 0;

function next(){
    var id = "box-galery-thumbs";
    var container = document.getElementById(id);
    var thumbs=document.getElementById(id).getElementsByTagName('img').length;
    container.style.width = (thumbs * 53)+"px"; 
    var deslocamento = parseInt(thumbs-8) * 51;
    if (margin >= -(deslocamento)&& thumbs > 8) {
        margin -= 53;
        document.getElementById(id).style.left = margin + "px";
    }
}
 
function prev(){
    var id = "box-galery-thumbs";
    if (margin != 0) {
        margin += 53;
        document.getElementById(id).style.left = margin + "px";
    }
}