/* Copyright: ----------------------------------------------------------------------------------------------------------------------------------------
PrimoThemes.com, WebSharks Inc. ( http://www.primothemes.com/ )
-- Modifications: ------------------------------------------------------------------------------------------------------------------------------------
You are authorized to make any necessary modification(s) to our products to fit your purposes.
However, you may NOT re-distribute or release any modifications as GPL or otherwise.
You are also NOT allowed to delete our credit text from the top of this file.
-- Unauthorized Use: ---------------------------------------------------------------------------------------------------------------------------------
You may not place any of our products, modified or unmodified, on a diskette, CD, website or any other
medium and offer them for re-distribution or re-sale of any kind without prior written consent.
--------------------------------------------------------------------------------------------------------------------------------------------------- */
/*
This function opens a link in a new window according the options passed in.
Example usage: jQuery('a#linkid').winOpen ({width: 300, height: 300, center: 1});
Options can be passed as shown in the example above, or they could also be set using
the rel attribute like this: rel="winopen;options={width: 300, height: 300, center: 1}"
In addition, this plugin will automatically attach click events for winopen() to any
link: a[rel^="winopen"], saving you the trouble of setting it up yourself.
*/
(function(jQuery)
 {
  jQuery.fn.winOpen = function(options)
   {
    var popup, jQthis = jQuery(this), defaults = {top: 0, left: 0, name: '_popup', width: ((screen.width >= 1280) ? 1280 : screen.width), height: ((screen.height >= 768) ? 768 : screen.height), resizable: 1, toolbar: 0, scrollbars: 1, status: 0, center: 1, location: 0, menubar: 0};
    /**/
    options = jQuery.extend (defaults, options);
    /**/
    var paramsSeparator = ';'; /* Separates the parameters, ex: winopen;options={} */
    var optionsRegex = /(options)( ?)(\=)( ?)(\{)(.+)(\})/i; /* Regex for parsing out the options. */
    var optionsSeparator = ','; /* Separates the options, ex: width:300, height:300, name:'_popup' */
    var optionRegex = /([a-z_]+)( ?)(\:)( ?)('?)([^'$]*)('?)/i; /* Regex for parsing an option. */
    /**/
    var rel = jQthis.attr ('rel'); /* Lets get the rel attribute for this. */
    rel = ( typeof rel === 'string') ? rel : ''; /* Be sure rel is a string. */
    /**/
    var prms, p, pl, m, opts, o, ol; /* Here we parse the options out. */
    if (rel.match (/^winopen/i) && ((prms = rel.split (paramsSeparator)).length))
     for (p = 0, pl = prms.length; p < pl; p++) /* Go through params, looking for options. */
      if ((m = prms[p].match (optionsRegex)) && ((opts = m[6].split (optionsSeparator)).length))
       for (o = 0, ol = opts.length; o < ol; o++) /* Go through options and get values. */
        if (m = opts[o].match (optionRegex)) /* Be sure to trim these up just in case. */
         options[jQuery.trim (m[1])] = jQuery.trim (m[6]);
    /**/
    if (options.center == 1) /* Adjust top and left if we are centering the window. */
     options.top = (screen.height-options.height) / 2, options.left = (screen.width-options.width) / 2;
    /**/
    var parameters = 'location='+options.location+',menubar='+options.menubar+',height='+options.height+',width='+options.width+',toolbar='+options.toolbar+',scrollbars='+options.scrollbars+',status='+options.status+',resizable='+options.resizable+',left='+options.left+',screenX='+options.left+',top='+options.top+',screenY='+options.top;
    /**/
    if (!(popup = window.open (jQthis.attr ('href'), options.name, parameters))) /* Lets catch blocks. */
     alert('Ot oh! It looks like you have a popup blocker preventing the window from opening. Please turn off all popup blockers and try again.');
    /**/
    else /* Else we just need to focus. */
     popup.focus ();
   };
 })(jQuery);
/*
In addition, this plugin will automatically attach click events for winopen() to any
link: a[rel^="winopen"], saving you the trouble of setting it up yourself.
*/
jQuery(document).ready (function ()
 {
  jQuery('a[rel^="winopen"]').bind ('click', function(e)
   {
    jQuery(this).winOpen ();
    return false;
   });
 });