jQuery(document).ready(function() {
    //FUNÇÕES PARA MUDAR O VALOR DOS DROPDOWNS, CRIADAS POR FILIPE HENRIQUE GONÇALVES.
    //========================================================================
    jQuery('ul.mnbarDrop > li > ul > li > a').click(function() {
        jQuery(this).parent().parent().parent().children('a:first').attr('title', jQuery(this).html());
        jQuery(this).parent().parent().parent().children('a:first').html(jQuery(this).html());

        jQuery('ul.mnBarNavDrop').css('display', 'none');

        if (jQuery(this).attr("lang") == "true") {
            postField(jQuery(this).attr("rel"), jQuery(this).attr("rev"));
        }
        else {
            selectField(jQuery(this).attr("rel"), jQuery(this).attr("rev"));
        }
    });
    jQuery('ul.mnbarDrop').hover(function() {
        jQuery('ul.mnBarNavDrop', this).css('display', 'block');
    },
    function() {
        jQuery('ul.mnBarNavDrop', this).css('display', 'none');
    }
    );

    //CATEGORIAS - DDL ESTADOS
    jQuery('ul#listNavEstados li a').click(function() {
        jQuery('.ddlEstados').val(jQuery(this).html());
        jQuery('ul#listNavEstados').css('display', 'none');
    });

    //FALE CONOSCO - DDL ÁREAS
    jQuery('ul.listNavAreas li a').click(function() {
        jQuery('.areaContato').val(jQuery(this).html());
        jQuery('ul.listNavAreas').css('display', 'none');
    });
    //========================================================================
	

});

	// iframe Pai - (http://benalman.com/code/projects/jquery-postmessage/examples/iframe/)
	$(function(){ 
	  var if_height;  
	  $.receiveMessage(function(e){
		alert('recebi mensagem');
		
		// Get the height from the passsed data.
		var h = Number( e.data.replace( /.*if_height=(\d+)(?:&|$)/, '$1' ) );
		
		if ( !isNaN( h ) && h > 0 && h !== if_height ) {
		if (h < 500) { h= 500;}
		  // Height has changed, update the iframe.
		  $('#frameFilho').height( if_height = h );
		}
		
	  // An optional origin URL (Ignored where window.postMessage is unsupported).
	  }, 'http://rosapacini.com.br/' );
	  
	  
	});


function postField(hiddenFieldID, val) {
    if (hiddenFieldID != null && hiddenFieldID != "") {
        var hiddenField = document.getElementById(hiddenFieldID);
        if (hiddenField) {
            hiddenField.value = val;
            __doPostBack(hiddenFieldID, '');
        }
    }
}

function selectField(hiddenFieldID, val) {
    if (hiddenFieldID != null && hiddenFieldID != "") {
        var hiddenField = document.getElementById(hiddenFieldID);
        if (hiddenField)
            hiddenField.value = val;
    }
}

// FAQ
$(document).ready(function(){
	$("#accordion").accordion({ active:false, collapsible:true, autoHeight:false });
	$("#accordionSantos").accordion({ active:false, collapsible:true, autoHeight:false }); 
	$("#accordionImbituba").accordion({ active:false, collapsible:true, autoHeight:false });
	$("#accordionVilaConde").accordion({ active:false, collapsible:true, autoHeight:false });
	$("#accordionTEV").accordion({ active:false, collapsible:true, autoHeight:false });
	$("#accordionLogistica").accordion({ active:false, collapsible:true, autoHeight:false });
});

// SubMenu Topo
window.onload = function() {
    horizontal();
	horizontalIngles();
    SubMenuInterna();
    comboCameras();
    //comboMenor();
    //comboMes();
    //comboCategoria();
    comboVaga();
    comboOpcao2();
    comboOpcao3();
}

// Menu Horizontal Português
function horizontal() {
    $('#menu_dropdown li').each(function() {
        if ($(this).hasClass('submenu')) {
            $(this).mouseover(function() {
                $(this).children('ul').show();
                $(this).children('a:first').css('background', 'url(/util/img/' + $(this).attr('id') + '.gif) 0 0 no-repeat');
                $(this).children('ul:first').css('background', 'url(/util/img/bgSubmenu_' + $(this).attr('id') + '.gif) 0 0 no-repeat');
            });
            $(this).mouseout(function() {
                $(this).children('ul').hide();
                $(this).children('a:first').css('background', 'none');
            });
        }
    });
}

// Menu Horizontal Inglês
function horizontalIngles() {
   $('#menu_dropdown li').each(function() {
		if($(this).hasClass('submenuIngles')) {
			$(this).mouseover(function(){
				$(this).children('ul').show();
				$(this).children('a:first').css('background','url(/util/img/eng/'+$(this).attr('id')+'.gif) 0 0 no-repeat');
				$(this).children('ul:first').css('background','url(/util/img/eng/bgSubmenu_'+$(this).attr('id')+'.gif) 0 0 no-repeat');
			});
			$(this).mouseout(function(){
				$(this).children('ul').hide();
				$(this).children('a:first').css('background','none');
			});
		}
	});
}



// SubMenu Páginas Internas
function SubMenuInterna() {
    $("#subHomeMnInt li a").click(function() {
        if ($(this).parent().find("ul").length > 0) {
            if ($(this).parent().find("ul:hidden").length > 0) {
                $(this).parent().parent().find("ul").slideUp();
                $(this).parent().parent().find("a").removeClass('active');
                $(this).addClass('active');
                $(this).nextAll('ul').slideDown();
            }
            else {
                $(this).removeClass('active');
                $(this).nextAll('ul').slideUp();
            }
            return false;
        }
    });
}

// Combo Câmeras
function comboCameras() {
    var navItems = document.getElementById("barra");

    if (!navItems) return false;

    navItems = navItems.getElementsByTagName("li");

    for (var i = 0; i < navItems.length; i++) {
        if ((navItems[i].className == "mnCameraVert") || (navItems[i].className == "mnCameraSub")) {
            if (navItems[i].getElementsByTagName('ul')[0] != null) {
                navItems[i].onmouseover = function() { this.getElementsByTagName('ul')[0].style.display = "block"; this.className = "mnCameraOn"; }
                navItems[i].onmouseout = function() { this.getElementsByTagName('ul')[0].style.display = "none"; this.className = "mnCameraVert"; }
            }
        }
    }

}

// Combo Menor
function comboMenor() {
    var navItems = document.getElementById("barraMenor");

    if (!navItems) return false;

    navItems = navItems.getElementsByTagName("li");

    for (var i = 0; i < navItems.length; i++) {
        if ((navItems[i].className == "mnCameraVertMenor") || (navItems[i].className == "mnCameraSubMenor")) {
            if (navItems[i].getElementsByTagName('ul')[0] != null) {
                navItems[i].onmouseover = function() { this.getElementsByTagName('ul')[0].style.display = "block"; this.className = "mnCameraOnMenor"; }
                navItems[i].onmouseout = function() { this.getElementsByTagName('ul')[0].style.display = "none"; this.className = "mnCameraVertMenor"; }
            }
        }
    }

}

// Combo Mês
function comboMes() {
    var navItems = document.getElementById("barraMes");

    if (!navItems) return false;

    navItems = navItems.getElementsByTagName("li");

    for (var i = 0; i < navItems.length; i++) {
        if ((navItems[i].className == "mnCameraVertMes") || (navItems[i].className == "mnCameraSubMes")) {
            if (navItems[i].getElementsByTagName('ul')[0] != null) {
                navItems[i].onmouseover = function() { this.getElementsByTagName('ul')[0].style.display = "block"; this.className = "mnCameraOnMes"; }
                navItems[i].onmouseout = function() { this.getElementsByTagName('ul')[0].style.display = "none"; this.className = "mnCameraVertMes"; }
            }
        }
    }

}

// Combo Categoria
function comboCategoria() {
    var navItems = document.getElementById("barraCategoria");

    if (!navItems) return false;

    navItems = navItems.getElementsByTagName("li");

    for (var i = 0; i < navItems.length; i++) {
        if ((navItems[i].className == "mnCameraVertCategoria") || (navItems[i].className == "mnCameraSubCategoria")) {
            if (navItems[i].getElementsByTagName('ul')[0] != null) {
                navItems[i].onmouseover = function() { this.getElementsByTagName('ul')[0].style.display = "block"; this.className = "mnCameraOnCategoria"; }
                navItems[i].onmouseout = function() { this.getElementsByTagName('ul')[0].style.display = "none"; this.className = "mnCameraVertCategoria"; }
            }
        }
    }

}

// Combo Vaga
function comboVaga() {
    var navItems = document.getElementById("barraVaga");

    if (!navItems) return false;

    navItems = navItems.getElementsByTagName("li");

    for (var i = 0; i < navItems.length; i++) {
        if ((navItems[i].className == "mnCameraVertCategoria") || (navItems[i].className == "mnCameraSubCategoria")) {
            if (navItems[i].getElementsByTagName('ul')[0] != null) {
                navItems[i].onmouseover = function() { this.getElementsByTagName('ul')[0].style.display = "block"; this.className = "mnCameraOnCategoria"; }
                navItems[i].onmouseout = function() { this.getElementsByTagName('ul')[0].style.display = "none"; this.className = "mnCameraVertCategoria"; }
            }
        }
    }

}

// Combo opcao2
function comboOpcao2() {
    var navItems = document.getElementById("barraOpcao2");

    if (!navItems) return false;

    navItems = navItems.getElementsByTagName("li");

    for (var i = 0; i < navItems.length; i++) {
        if ((navItems[i].className == "mnCameraVertCategoria") || (navItems[i].className == "mnCameraSubCategoria")) {
            if (navItems[i].getElementsByTagName('ul')[0] != null) {
                navItems[i].onmouseover = function() { this.getElementsByTagName('ul')[0].style.display = "block"; this.className = "mnCameraOnCategoria"; }
                navItems[i].onmouseout = function() { this.getElementsByTagName('ul')[0].style.display = "none"; this.className = "mnCameraVertCategoria"; }
            }
        }
    }

}

// Combo opcao3
function comboOpcao3() {
    var navItems = document.getElementById("barraOpcao3");

    if (!navItems) return false;

    navItems = navItems.getElementsByTagName("li");

    for (var i = 0; i < navItems.length; i++) {
        if ((navItems[i].className == "mnCameraVertCategoria") || (navItems[i].className == "mnCameraSubCategoria")) {
            if (navItems[i].getElementsByTagName('ul')[0] != null) {
                navItems[i].onmouseover = function() { this.getElementsByTagName('ul')[0].style.display = "block"; this.className = "mnCameraOnCategoria"; }
                navItems[i].onmouseout = function() { this.getElementsByTagName('ul')[0].style.display = "none"; this.className = "mnCameraVertCategoria"; }
            }
        }
    }

}


// Aplica Flash
function aplicaFlash(swf, width, height, wmode, cache, flashVars) {
    var noCache = "";
    if (cache == undefined || cache == '') { var noCache = "?" + new Date(); }
    if (wmode != "opaque" && wmode != "transparent") { wmode = "transparent"; }
    var monta_swf = "";
    monta_swf += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + width + "' height='" + height + "' title=''>";
    monta_swf += "<param name='movie' value='" + swf + noCache + "' />";
    monta_swf += "<param name='quality' value='high' />";
    monta_swf += "<param name='menu' value='0' />";
    monta_swf += "<param name='wmode' value='" + wmode + "' />";
    monta_swf += "<param name='flashVars' value='" + flashVars + "' />";
    monta_swf += "<embed src='" + swf + noCache + "' quality='high' wmode='" + wmode + "' flashVars='" + flashVars + "' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + width + "' height='" + height + "'></embed>";
    monta_swf += "</object>";
    document.write(monta_swf);
}

// Lightbox
function abrirLightBox(ind) {
    // START - SIMPLE MODAL jQuery	
    $('.window .close, #mask').click(function(e) {
        $('.window').fadeOut('normal', function() {
            $('#mask').fadeOut('normal');
        });
        e.preventDefault();
    });


    var id = ind;
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    $('#mask').css({
        'width': maskWidth,
        'height': maskHeight,
        'background': '#000',
        'opacity': 0.8,
        'cursor': 'pointer'
    });


    $('#mask').fadeIn();

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    $(id).css('top', winH / 2 - $(id).height() / 2);
    $(id).css('left', winW / 2 - $(id).width() / 2);

    $(id).fadeIn(2000);

    // END - SIMPLE MODAL jQuery
}

function Alterafoto(imgSrc) {
    $('#imgPrincipal').attr("src", imgSrc);
}

function onYouTubePlayerReady(playerId) {
    ytplayer = document.getElementById("myytplayer");
}

function flash(id) {
	var swf = "http://www.youtube.com/v/" + id + "?enablejsapi=1&playerapiid=ytplayer";
	
	var noCache = "?" + new Date();
    var monta_swf = "";
    monta_swf += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='300' height='220' title=''>";
    monta_swf += "<param name='movie' value='" + swf + noCache + "' />";
    monta_swf += "<param name='quality' value='high' />";
    monta_swf += "<param name='menu' value='0' />";
    monta_swf += "<param name='wmode' value='transparent' />";
    monta_swf += "<embed src='" + swf + noCache + "' quality='high' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='300' height='220'></embed>";
    monta_swf += "</object>";
    document.getElementById('galeriaPrincipal').innerHTML = monta_swf;
}

function flash2(id) {
    ytplayer = document.getElementById("myytplayer");
    ytplayer.loadVideoById(id);
}


$(document).ready(function(){
    if($('#chkTodo').is(':checked'))
	{
        document.formBusca.action = document.getElementById('hidBusca').value;
	
	} else {
        document.formBusca.action = (document.getElementById('hidBuscaRI').value);
	
	}

});


function TipoBusca()
{
    if (document.getElementById('chkTodo').checked)
    {
        document.formBusca.action = document.getElementById('hidBusca').value;
    }
    else
    {
        document.formBusca.action = (document.getElementById('hidBuscaRI').value);
    }
}




$(function(){
  
  // Keep track of the iframe height.
  var if_height;
  
    // Pass the parent page URL into the Iframe in a meaningful way (this URL could be
    // passed via query string or hard coded into the child page, it depends on your needs).
    
    // Append the Iframe into the DOM.
    //iframe = $('#frameFilho');
  
  // Setup a callback to handle the dispatched MessageEvent event. In cases where
  // window.postMessage is supported, the passed event will have .data, .origin and
  // .source properties. Otherwise, this will only have the .data property.
  $.receiveMessage(function(e){
    // Get the height from the passsed data.
    var h = Number( e.data.replace( /.*if_height=(\d+)(?:&|$)/, '$1' ) );
    
    if ( !isNaN( h ) && h > 0 && h !== if_height ) {
      // Height has changed, update the iframe.
	  if (h < 500) { h = 500 };
	  h = Math.floor(h * 1.1);
      $('#frameFilho').height( if_height = h );
	  //iframe.height( if_height = h );
    }
    
  // An optional origin URL (Ignored where window.postMessage is unsupported).
  }, 'http://www.mzweb.com.br' );
  
  
});
