﻿$(document).ready(function() {

    

    $(".showGallery").click(function(){
        $(".first:first").click();
    });

    $(".trOrg").hide();
    $(".org").change(function(){
        if($(this).val()=='Annet'){
            //$(".trOrg").toggle();
            
            
            var elem = $(".trOrg")[0]; 
            if(elem.style.display == 'none') 
                 $(elem).show(); 
            else 
            { 
                 $(elem).hide();                        
            }
        }
    });



    
    $(".pName").click(function(){
    
        
       
        
        var elem = $(this).parent().next()[0]; 
        if(elem.style.display == 'none') 
             $(elem).show(); 
        else 
        { 
             $(elem).hide();                        
        } 

        
        //$(this).parent().next().toggle();
        $(this).toggleClass("accActvie",1000);
    });
    
    
    $(".time input").not(".numb").click(function(){
        $(this).next().next().toggle();
        $(this).next().next().next().toggle();
    });
    
    $(".numb").hide();
    $(".numb").prev().hide();
    
    $(".numb").each(function(){
        $(this).change(function(){
            var val = $(this).prev().prev().prev().val();
            val = val.substring(0,val.lastIndexOf(":")+1);
            val += $(this).val()+" stk";
            $(this).prev().prev().prev().val(val);
        });
    });
    
    
    
    StyleButton("btnBuy");
    

    //gallerific
    if($('#thumbs').html()!=null){


        // Initially set opacity on thumbs and add
        // additional styling for hover effect on thumbs
        var onMouseOutOpacity = 0.67;
        $('#thumbs ul.thumbs li').opacityrollover({
	        mouseOutOpacity:   onMouseOutOpacity,
	        mouseOverOpacity:  1.0,
	        fadeSpeed:         'fast',
	        exemptionSelector: '.selected'
        });
        
        // Initialize Advanced Galleriffic Gallery
        
        
        
	    var gallery = $('#thumbs').galleriffic({
		    delay:                     2500,
		    numThumbs:                 8,
		    preloadAhead:              10,
		    enableTopPager:            true,
		    enableBottomPager:         true,
		    maxPagesToShow:            7,
		    imageContainerSel:         '#slideshow',
		    controlsContainerSel:      '#controls',
		    captionContainerSel:       '#caption',
		    loadingContainerSel:       '#loading',
		    renderSSControls:          true,
		    renderNavControls:         true,
		    playLinkText:              'Play Slideshow',
		    pauseLinkText:             'Pause Slideshow',
		    prevLinkText:              '&lsaquo; Previous Photo',
		    nextLinkText:              'Next Photo &rsaquo;',
		    nextPageLinkText:          'Next &rsaquo;',
		    prevPageLinkText:          '&lsaquo; Prev',
		    enableHistory:             false,
		    autoStart:                 false,
		    syncTransitions:           true,
		    defaultTransitionDuration: 900,
            onSlideChange: function(prevIndex, nextIndex) {
            // 'this' refers to the gallery, which is an extension of $('#thumbs')
            this.find('ul.thumbs').children()
	            .eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
	            .eq(nextIndex).fadeTo('fast', 1.0);
            },
            onPageTransitionOut:       function(callback) {
            this.fadeTo('fast', 0.0, callback);
            },
            onPageTransitionIn:        function() {
            this.fadeTo('fast', 1.0);
            }
        });
    }
    



    $("a.movie").each(function(){
        $(this).append('<img src="/templates/fib/styles/images/ico_videoElement.png" alt="Play" class="ico" />');
    });

    $("a.zoom").not(".first").hide();
    $("a.zoom").fancybox();


    jQuery(".searchInput").each(function() {
        $(this).defaultValue($(this).attr('title'));
    });



    $('.searchInput').keypress(function(e) {
        var code = null;
        code = (e.keyCode ? e.keyCode : e.which);
        if (code == 13) {
            e.preventDefault();
            $('.searchBtn').click();
        }

    });
    

    $('.DatePicker').datepicker({dateFormat: 'dd.mm.yy', minDate:new Date()});    
    
    $('.dllType').selectbox();


    //editor webpart
    $("[id*=_cboAvailableWebParts] option:contains('LongStringWebPart'), span[title='LongStringWebPart']").each(function(){
        $(this).text('Editor');
    });
    
    
    //galleri
    $('.slide').cycle({ 
        fx:    'fade', 
        pause:  1 
    });
    
    
    //Background-material dropdown
    $('li.headlink ul').hide();
    $('li.headlink').hover(
			function() { $('ul', this).show(); },
			function() { $('ul', this).hide(); }
	);

});



function PlayMovie( movie, width, height){
    flowplayer('movie', {

        // our Flash component
        src: "/Templates/fib/Scripts/FlowPlayer/flowplayer-3.1.2.swf",

        // we need at least this Flash version 
        version: [9, 115],

        // older versions will see a custom message 
        onFail: function() {
            $("#info").innerHTML =
            "You need the latest Flash version to see MP4 movies. " +
            "Your version is " + this.getVersion();
        }
        // here is our third argument which is the Flowplayer configuration 
    }, {
        clip: {            
            autoPlay: false,
            autoBuffering: true,
            url: movie            
        },          
        // default controls with the same background color as the page background     
        plugins:  {           
            controls:  {             
                    backgroundColor: '#ffffff',             
                    backgroundGradient: 'none',                         
                    all: false,             
                    scrubber: true, 
                    mute:true,            
                    height: 30,             
                    sliderColor: '#333333',             
                    progressColor: '#eaeaea',             
                    bufferColor: '#666666'         
                    }     
              },          
       // fiercy red background color with a little gradient and curving     
       canvas: {         
                backgroundColor: '#ffffff',         
                backgroundGradient: [0.3, 0],         
                borderRadius: 0     }
                ,          
                       // set screen dimensions so that it goes near the canvas borders     
                       screen: {         
                                width: width,         
                                height: height,          
                                top: 3     
                                }      
       });
}

function StyleButton(className){
   
   var submitText = jQuery("input."+className).val();
   $("input."+className).hide();
   $("input."+className).parent().append('<p><a href="#" class="'+className+' tickets ticketsno"><span class="'+className+'">'+submitText+'</span></a></p>');
   
   
   
   $("a."+className).click(function(){ 
        jQuery(".defaulttext").each(function() {
            if($(this).val()==$(this).attr('title')){
                $(this).val('');
            }
           
        }); 
       $("input."+className).click();
     }); 
}

function share(type){
    var url = location.href;
    var title = document.title;
    var description = '';
    var metas = document.getElementsByTagName('meta');
    for (var x=0,y=metas.length; x<y; x++) {
      if (metas[x].name.toLowerCase() == "description") {
        description = metas[x];
      }
    }
    
    if(type==1){
        window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&amp;t='+encodeURIComponent(title),'facebookshare','toolbar=0,status=0,width=626,height=436');return false;
    }else if(type==2){
        window.open('http://www.nettby.no/user/edit_link.php?name=' + escape(title) + '&url=' + escape(url) + '&amp;description=' + escape(description), 'nettbyshare', 'scrollbars=no,width=450,height=430');
    }else if(type==3){
        window.open('http://www.stumbleupon.com/submit?title=' + escape(title) + '&url=' + escape(url), 'stumbleuponshare', 'scrollbars=yes,width=790,height=430');
    }else if(type==4){
        window.open('http://digg.com/submit?title=' + escape(title) + '&url=' + escape(url), 'diggshare', 'scrollbars=yes,width=790,height=430');
    }else if(type==5){
        window.open('http://del.icio.us/post?title=' + escape(title) + '&url=' + escape(url), 'deliciousshare', 'scrollbars=yes,width=790,height=430');
    }else if(type==6){
        window.open('http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(title) + '&c=' + '&u=' + encodeURIComponent(url) + '&l=' + 3, 'MySpaceShare', 'scrollbars=yes,width=790,height=430');
    }
    return false;
}


function LoadMap(l,b) {
    $(document).ready(function() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(l, b), 12);
        map.addOverlay(new GMarker(new GLatLng(l, b)));
      }
  });
}