/*www.bellissima.imetec.com/hu*/
//GA
var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-473767-23']);
  _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);
})();
 
//Core
$(document).ready(function() {
	
	//Global vars
    var themedir = $GF.config.themedir = '/hu';
	$GF.config.multilanguage = false;
	$GF.config.subdirectory = true;
	
	//Commons
	openPrivacy();
	$('.scrollpane').jScrollPane({showArrows: false});

    //Single functions
    //Home-page
    if ( $GF.is.page() || $GF.is.page('index.php')) {
		
		$GF.swfWrite(
		{
			swf : {
				movie 	: 'index.swf',
				wrapper : 'intro-animation',
				width	: '100%',
				height	: '100%'
			}
		});	
	}
	
	if ($GF.is.page('home.php')) {
		
		//Contest Experience 2011
		openColorbox('experience-contest/intro-box.php');
		
		$GF.swfWrite(
		{
			swf : {
				movie 	: 'main.swf',
				wrapper : 'animation',
				width	: 990,
				height	: 580
			}
		});
	}
	
	if ($GF.is.page('company.php')) {
		
		$GF.swfWrite(
		{
			swf : {
				movie 	: 'header-company.swf',
				wrapper : 'animation',
				width	: 990,
				height	: 450
			}
		});
	}
	
    if ($GF.is.page('experience.php')) {

        $GF.swfWrite({
            swf: {
                movie: 'header-experience.swf',
                wrapper: 'animation',
                width: 990,
                height: 450
            }
        });
    }
	
	if ($GF.is.page('testimonial.php')) {
		
		$GF.swfWrite(
		{
			swf : {
				movie 	: 'header-testimonial.swf',
				wrapper : 'animation',
				width	: 990,
				height	: 450
			}
		});
	}
	
	if ($GF.is.page('products.php')) {
		
		$GF.swfWrite(
		{
			swf : {
				movie 	: 'header-products.swf',
				wrapper : 'animation',
				width	: 990,
				height	: 450
			}
		});
	}
	
	if($(".product").length){
		
		productPageAnimation();
		
	}
	
	if ($GF.is.page('contacts.php')) {
		
		$GF.swfWrite(
		{
			swf : {
				movie 	: 'header-company.swf',
				wrapper : 'animation',
				width	: 990,
				height	: 450
			}
		});
		//Validate form
		$GF( '#frm-contacts' ).validate();
	}
	
	if ($GF.is.page('media.php')) {
		
		$GF.swfWrite(
		{
			swf : {
				movie 	: 'header-media.swf',
				wrapper : 'animation',
				width	: 990,
				height	: 450
			}
		});
		
		mediaVideo();
	}

})

/*-------------------- FUNCTIONS ---------------------------*/

function openPrivacy() {
	$('#privacy').click(function(){
		window.open('privacy.php','Terms & Conditions','width=520, height=500, ,toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=no');
		return false;
	})
}

function productPageAnimation() 
{

    //Split url
    /* 
    var url     = window.location.pathname;
    var page    = url.split('/').reverse();
    var product = page[0].split( '.' );
    var $prod   = $( "." + product[0].split( '.' ) );
    */
    
    var page    = $GF.get.page().replace( '.php', '' );
    var $prod   = $( '.' + page ).addClass( 'selected' ); 
    var article = $prod.closest( 'ul' ).attr('id');
    
    var menus = $.map( $( '#styles' ).children(), function( n, i )
    {
        return n.nodeName.toLowerCase() == 'div' ? $( n ).find( 'ul' )[0].id : null;
    });
    
    var index = $.inArray( article, menus );
    
	//Select main-menu label
	$('#main-menu ul li').eq(1).addClass("current-menu-item");
	
    //Initialize accordion
    $( '.prod-sidemenu' ).accordion( {
        active : index
    } );

    
    //Animate slides
    $GF.fn.slides( {
        menu        : '#slides-menu',
        slider      : '#slides-list',
        width       : 710,
        speed       : 800,
        applyClass  : 'parent'
   });
    
    //Write header
    $GF.swfWrite({
            swf : {
                movie   : page +'.swf',
                wrapper : 'animation',
                width   : 990,
                height  : 450
            }
    });
}

//@usage: media
function mediaVideo() {

    var $videoThumb = $(".video");
	var speed = 300;
	
	$videoThumb.hover(function() {

		$(this).siblings().stop().fadeTo(speed,0.4)
        }, function() {
        $(this).siblings().stop().fadeTo(speed,1)
        })

        $videoThumb.find('a').click(function() {

        	var $this = $(this);
        	var thisvideo = $this.attr("href");
			var w = $this.attr("rel").split(",")[0];
			var h = $this.attr("rel").split(",")[1];

        	popupVideo(thisvideo, w, h);

        return false;
    })
}

//@usage: open popup
function popupVideo(el, width, height) {
    
	$.fn.colorbox({
        opacity: 0.65,

        html: function() {
            return '<div id="media-video" style="background:#000; width:' + width + 'px; height:' + height + 'px;"></div>';
        },

        onComplete: function() {

            $GF.swfWrite({

                swf: {
                    movie: 'StrobeMediaPlayback.swf',
                    wrapper: 'media-video',
					width			: width,
					height			: height
                },

                flashvars: {
                    src: '../media/video/' + el + '&autoHideControlBar=true&loop=true&autoPlay=true&playButtonOverlay=true'

                }

            })
            }

    })
}

//@usage: open colorbox
function openColorbox(el) {

$.fn.colorbox({
        
		opacity: 0.8,

        href: function() {
            return './assets/ajax/'+el;
        }

   })
}
