var url_data = $("[jsdata]").attr("jsdata");
url_data=url_data.replace(/,$/g,'');
var mypost = eval('(' + "{" + url_data +"}" + ')');
//-----------------------------------------------
if (mypost['pagetype']=='mls_search') loadjsfile('mls-search.js');

function loadjsfile(filename){
  $("[jsdata]").before('<script type="text/javascript" src="/static/js/'+filename+'"></script>');
}

function loadcssfile(filename){
  $("[jsdata]").before('<link rel="stylesheet" type="text/css" href="/static/js/'+filename+'" />');
}

if ('managemode' in mypost) var in_editmode=0;

if (mypost['googlea']){
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', mypost['googlea'] ]);
    _gaq.push(['_trackPageview']);      
    (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();      
}

function resize_iframe(){
    if (parent.socket && gup('embed')){        
		parent.socket.postMessage(document.body.clientHeight || document.body.offsetHeight || document.body.scrollHeight);				  
    }	
}

function call_box_url(url, options){   
    var data={
         href: url,
		 scrolling: 'no',
	     padding: 0,
         onComplete: function(links, index) {
             setTimeout(function(){
                 $.fancybox.center(true);
             },1);             
         }
     };
     if (options) data=$.extend(data,options);
     $.fancybox(data);        
}

function call_box(obj,options){
    var data={ 
	     padding: 0,
		 scrolling: 'no',
         onComplete: function(links, index) {
             setTimeout(function(){ $.fancybox.center(true); },1);             
         }
     };
     if (options) data=$.extend(data,options);
     obj.fancybox(data);    
}

function gup( name ){
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
      return "";
    else
      return results[1];
 }
 
function changeimage_be(url){ call_box_url(url); }

function markitem(id){ $("#item_"+id).addClass("subactive"); }
function unmarkitem(id){ $("#item_"+id).removeClass("subactive"); }
function show_menu(pid){
    var rnd=Math.floor(Math.random()*110000)+1;
    $.get('/getsubpages/'+pid+'/'+rnd, function(msg){
        $("#submenu").html(msg);
        var mi=$("#menuitem_"+pid).offset();
        $("#submenu").css({ top: (mi.top+35)+'px', left: (mi.left+20)+'px' });
        $("#menuitem_"+pid).addClass("activemi");
        $("#submenu").attr("rel","menuitem_"+pid);
        $("#submenu").show();
    });
}

function create_simple_range(obj, minselect, maxselect, label, donttriggerformsubmit){		
    var created=0;
    var size = minselect.find("option").size();
	//alert(maxselect.val());
	var maxval=size;	
	if (maxselect.val()) maxval=maxselect.find(":selected").index()+1;	
	var minval=1;
	if (minselect.val()) minval=minselect.find(":selected").index();
	
    var internalslider_obj = obj.slider({
        range: true,
        values: [ minval,maxval ],
        min: 1,        
        max: size,        
        slide: function(event, ui){
            minselect.find("option:selected").removeAttr("selected");
			maxselect.find("option:selected").removeAttr("selected");	
            minselect.find("option").eq(ui.values[0]-1).attr("selected",true);
            maxselect.find("option").eq(ui.values[1]-1).attr("selected",true);
//			minselect.find("option").eq(ui.values[0]-1).attr("selected","selected");
//            maxselect.find("option").eq(ui.values[1]-1).attr("selected","selected");				
            label.html(minselect.find(":selected").html()+'      to     '+maxselect.find(":selected").html());		
        },		
        stop: function(){			
			if (!donttriggerformsubmit) formsubmit();
		}
    });        
    obj.bind('init',function(){
        label.html(minselect.find(":selected").html()+'     to     '+maxselect.find(":selected").html());    
    });
    obj.trigger('init');    
}
function create_simple_slider(obj, minselect, label){		
    var size = minselect.find("option").size();		
    var internalslider_obj = obj.slider({
        min: 1,
        max: size,
        range: 'min',
        value: [ 1 ],
        slide: function(event, ui){
            minselect.find("option:selected").removeAttr("selected");				
            minselect.find("option").eq(ui.value-1).attr("selected","selected");				
            label.html(minselect.find(":selected").html());
        }		,
        stop: function(){ formsubmit(); }
    });    
    if (minselect.val()) internalslider_obj.slider("value",minselect.find(":selected").index());        
    minselect.change(function() { internalslider_obj.slider( "value",0, this.selectedIndex + 1 ); });    
    label.html(minselect.find(":selected").html());    
}	

$(document).ready(function(){
	
	if (gup('embed')){
		var gu_param=gup('embed');
		$("a").each(function(){
		   var current=$(this).attr("href");
		   if ($(this).hasClass('pageturn')){			
		   } else {
		       if (typeof(current)=='string' && current.indexOf('?embed=')<0){
		           $(this).attr("href",current+'?embed='+gu_param);
               }
		   }
		});

		setTimeout(function(){
		  parent.socket.postMessage(document.body.clientHeight || document.body.offsetHeight || document.body.scrollHeight);		
		},1500);		
	}
	
	
    call_box($(".boxlink"));
    if (mypost['managemode']) call_box($("#admin_orderbtn"));
    
    $("#mainmenu li").hover(function(){
        $(this).find(".submenu").show();
    }, function(){
        $(this).find(".submenu").hide();
    });    
    if (mypost['brokerageuser']){	
        //$("body").append('<div id="claimlink"><a  href="/claimbox"><img src="/static/images/claim_my_site.png"></a></div>');
        //call_box($("#claimlink a"));        
    }    
    $("#submenu li a").hover(function(){
        $(this).parent().parent().addClass("subactive");
    },function(){
        $(this).parent().parent().removeClass("subactive");
    });
    $(".mainmenu li").hover(function(){ if (!$(this).hasClass("activemi")) $("#submenu").hide(); });
    $("#submenu").mouseleave(function(){
        var id=$("#submenu").attr("rel");
        $("#"+id).removeClass("activemi");
        $("#submenu").hide();
    });    
    $(".shift").baseshift();
    $("[tooltip]").tooltip();
	
    call_box($(".contact_me"));
    
    if (mypost['apage']=='blog') call_box($(".optionbox"));
    if (mypost['show_table2']){        
        $(".listings").tablesorter({  headers: {  0: { sorter: false } }});        			
        $(".listings tr").hover(function(){
            $(this).find("td").addClass("highlighted");
            $(this).unbind("click").click(function(){            
                if (mypost['managemode']){
                    if (in_editmode==0){
                        var url=$(this).find(".address_cell a").attr("href");
                        if (url) document.location.href=url;
                    }
                } else {
                    var url=$(this).find(".address_cell a").attr("href");
                    if (url) document.location.href=url;
                }            
            });
        }, function(){
            $(this).find("td").removeClass("highlighted");
            $(this).unbind("click");
        });        
    }       
    
    if ((mypost['pageurl']=='index')&&(mypost['sitename']=='barrypockay')){
        $("#crossslide").crossSlide({
            sleep: 4,
            width: '960px',
            height: '283px',
            fade: 3
        }, [            
            { src: '/static/media/crossslider/barry_banner1.jpg' },
            { src: '/static/media/crossslider/barry_banner2.jpg' },  
            { src: '/static/media/crossslider/barry_banner3.jpg' },
            { src: '/static/media/crossslider/barry_banner4.jpg' },
            { src: '/static/media/crossslider/barry_banner5.jpg' }                
        ]); 	
    }
    resize_iframe();
	
});

